package main

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

const MN = 21
const INF = 1e9+100
var a, ab [1<<MN]int
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

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

    var n uint
    fmt.Fscanln(inp, &n)

    s, _ := inp.ReadString('\n')
    s = strings.TrimSpace(s)

    u := strings.Split(s, " ")
    for i, v := range u {
        a[i], _ = strconv.Atoi(v)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    s, _ = inp.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        q[i], _ = strconv.Atoi(v)
    }

    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const N = 20

var (
	a   []int64 = make([]int64, (1<<N)+1)
	aux []int64 = make([]int64, (1<<N)+1)
	sum [N + 1][2]int64
)

func Reverse(a []int64, low int64, high int64) {
	for i := low; i <= (low+high)/2; i++ {
		a[i], a[high-i+low] = a[high-i+low], a[i]
	}
}

func LowerBound(a []int64, low, high int64, value int64) int64 {
	l, h := low, high
	pos := low - 1
	for l <= h {
		mid := (l + h) >> 1
		if value > a[mid] {
			l = mid + 1
			pos = mid
		} else {
			h = mid - 1
		}
	}
	return pos
}

func Merge(aux []int64, a []int64, low, mid, high int64) {
	for i, j, k := low, mid+1, low; k <= high; k++ {
		if j > high || i <= mid && aux[i] <= aux[j] {
			a[k] = aux[i]
			i++
		} else {
			a[k] = aux[j]
			j++
		}
	}
}
func Inversions(aux []int64, a []int64, low int64, high int64, deep int64) {
	if low >= high {
		return
	}
	mid := (low + high) >> 1
	Inversions(a, aux, low, mid, deep-1)
	Inversions(a, aux, mid+1, high, deep-1)
	count := int64(0)
	for i, j := low, mid; i <= mid; i++ {
		j = LowerBound(aux, j+1, high, aux[i])
		count = count + j - mid
	}
	sum[deep][0] = sum[deep][0] + count
	count = 0
	for i, j := mid+1, low-1; i <= high; i++ {
		j = LowerBound(aux, j+1, mid, aux[i])
		count = count + j - low + 1
	}
	sum[deep][1] = sum[deep][1] + count
	if aux[mid] <= aux[mid+1] {
		copy(a[low:high+1], aux[low:high+1])
		return
	}
	Merge(aux, a, low, mid, high)
}

func main() {
	var n, m, que int64
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	for {
		_, err := fmt.Fscan(r, &n)
		if err == io.EOF {
			break
		}
		for i := 0; i < len(sum); i++ {
			sum[i][0] = int64(0)
			sum[i][1] = int64(0)
		}
		length := int64(math.Pow(2, float64(n)))
		a[0] = length
		for i := int64(1); i <= length; i++ {
			fmt.Fscan(r, &a[i])
		}
		copy(aux, a)
		Inversions(aux, a, 1, a[0], n)
		fmt.Fscan(r, &m)
		for i := int64(1); i <= m; i++ {
			fmt.Fscan(r, &que)
			ans := int64(0)
			for i := que; i >= 1; i-- {
				sum[i][0], sum[i][1] = sum[i][1], sum[i][0]
			}
			for i := int64(0); i <= n; i++ {
				ans = ans + sum[i][0]
			}
			fmt.Fprintln(w, ans)
		}
	}
	w.Flush()
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func main() {
	inS := bufio.NewReader(os.Stdin)
	ouS := bufio.NewWriter(os.Stdout)
	defer ouS.Flush()
    var n uint
    fmt.Fscanln(inS, &n)
//    n = getUint(inS)
    for i := uint(0); i < 1<<n; i++ {
//    	fmt.Fscan(inS, &a[i])
//    	a[i] = getUint(inS)
    }
    s, _ := inS.ReadString('\n')
    s = strings.TrimSpace(s)
    u := strings.Split(s, " ")
    for i, v := range u {
        d, _ := strconv.ParseInt(v, 10, 32)
        a[i] = uint(d)
    }
    var m uint
    fmt.Fscanln(inS, &m)
//    m = getUint(inS)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
//	    fmt.Fscan(inS, &q[i])
//    	q[i] = getUint(inS)
    }
    s, _ = inS.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        d, _ := strconv.ParseInt(v, 10, 32)
        q[i] = uint(d)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += int64(v[0])
        }
        ouS.WriteString(strconv.FormatInt(r, 10))
        ouS.WriteByte('\n')
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func main() {
	inS := bufio.NewReader(os.Stdin)
	ouS := bufio.NewWriter(os.Stdout)
	defer ouS.Flush()
    var n uint
    fmt.Fscanf(inS, "%d\n", &n)
//    n = getUint(inS)
    for i := uint(0); i < 1<<n; i++ {
    	fmt.Fscanf(inS, "%d", &a[i])
//    	a[i] = getUint(inS)
    }
    fmt.Fscanf(inS, "\n")
    var m uint
    fmt.Fscanf(inS, "%d\n", &m)
//    m = getUint(inS)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
	    fmt.Fscanf(inS, "%d", &q[i])
//    	q[i] = getUint(inS)
    }
    fmt.Fscanf(inS, "\n")
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += int64(v[0])
        }
        ouS.WriteString(strconv.FormatInt(r, 10))
        ouS.WriteByte('\n')
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}
func main() {
	inp := bufio.NewReader(os.Stdin)
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func printUint64ln(b io.ByteWriter, d uint64) {
	var o [10]byte
	c := 0
	for d > 0 {
		o[c] = byte(d%10)+'0'
		d /= 10
		c++
	}
	if c == 0 {
		o[0] = '0'
		c = 1
	}
	for i := c-1; i >= 0; i-- {
		b.WriteByte(o[i])
	}
	b.WriteByte('\n')
	return
}
func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := uint64(0)
        for _, v := range num[:] {
            r += uint64(v[0])
        }
        fmt.Println(r)
        //printUint64ln(out, r)
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func main() {
	inS := bufio.NewReader(os.Stdin)
	ouS := bufio.NewWriter(os.Stdout)
	defer ouS.Flush()
    var n uint
    fmt.Fscan(inS, &n)
//    n = getUint(inS)
    for i := uint(0); i < 1<<n; i++ {
    	fmt.Fscan(inS, &a[i])
//    	a[i] = getUint(inS)
    }

    var m uint
    fmt.Fscan(inS, &m)
//    m = getUint(inS)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
	    fmt.Fscan(inS, &q[i])
//    	q[i] = getUint(inS)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += int64(v[0])
        }
        ouS.WriteString(strconv.FormatInt(r, 10))
        ouS.WriteByte('\n')
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func printUint64ln(b io.ByteWriter, d uint64) {
	var o [22]byte
	c := 0
	for d > 0 {
		o[c] = byte(d%10)+'0'
		d /= 10
		c++
	}
	if c == 0 {
		o[0] = '0'
		c = 1
	}
	for i := c-1; i >= 0; i-- {
		b.WriteByte(o[i])
	}
	b.WriteByte('\n')
	return
}
func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := uint64(0)
        for _, v := range num[:] {
            r += uint64(v[0])
        }
        //fmt.Println(r)
        printUint64ln(out, r)
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func printUint64ln(b io.ByteWriter, d uint64) {
	var o [22]byte
	c := 0
	for d > 0 {
		o[c] = byte(d%10)+'0'
		d /= 10
		c++
	}
	if c == 0 {
		o[0] = '0'
		c = 1
	}
	for i := c-1; i >= 0; i-- {
		b.WriteByte(o[i])
	}
	b.WriteByte('\n')
	return
}
func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += int64(v[0])
        }
        out.WriteString(strconv.FormatInt(r, 10))
        out.WriteByte('\n')
    }
}

package main

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

const MN = 21
const INF = 1<<40
var a, ab [1<<MN]int64
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

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

    var n uint
    fmt.Fscanln(inp, &n)

    s, _ := inp.ReadString('\n')
    s = strings.TrimSpace(s)

    u := strings.Split(s, " ")
    for i, v := range u {
        a[i], _ = strconv.ParseInt(v, 10, 64)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    s, _ = inp.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        q[i], _ = strconv.Atoi(v)
    }

    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const N = 20

var (
	a   []int64 = make([]int64, (1<<N)+1)
	sum [N + 1][2]int64
)

func Reverse(a []int64, low int64, high int64) {
	for i := low; i <= (low+high)/2; i++ {
		a[i], a[high-i+low] = a[high-i+low], a[i]
	}
}

func LowerBound(a []int64, low, high int64, value int64) int64 {
	l, h := low, high
	pos := low - 1
	for l <= h {
		mid := (l + h) >> 1
		if value > a[mid] {
			l = mid + 1
			pos = mid
		} else {
			h = mid - 1
		}
	}
	return pos
}

func InplaceMerge(a []int64, low int64, mid int64, high int64) {
	i, j := low, mid+1
	for i < j && j <= high {
		step := int64(0)
		for ; i < j && a[i] <= a[j]; i++ {
		}
		for ; j <= high && a[j] <= a[i]; j++ {
			step++
		}
		Reverse(a, i, mid)
		Reverse(a, mid+1, j-1)
		Reverse(a, i, j-1)
		i = i + step
	}
}

func Inversions(a []int64, low int64, high int64, deep int64) {
	if low >= high {
		return
	}
	mid := (low + high) >> 1
	Inversions(a, low, mid, deep-1)
	Inversions(a, mid+1, high, deep-1)
	count := int64(0)
	for i, j := low, mid; i <= mid; i++ {
		j = LowerBound(a, j+1, high, a[i])
		count += j - mid
	}
	sum[deep][0] += count
	count = 0
	for i, j := mid+1, low-1; i <= high; i++ {
		j = LowerBound(a, j+1, mid, a[i])
		count += j - low + 1
	}
	sum[deep][1] += count
	InplaceMerge(a, low, mid, high)
}

func main() {
	var n, m, que int64
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	for {
		_, err := fmt.Fscan(r, &n)
		if err == io.EOF {
			break
		}
		for i := 0; i < len(sum); i++ {
			sum[i][0] = int64(0)
			sum[i][1] = int64(0)
		}
		length := int64(math.Pow(2, float64(n)))
		a[0] = length
		for i := int64(1); i <= length; i++ {
			fmt.Fscan(r, &a[i])
		}
		fmt.Fscan(r, &m)
		Inversions(a, 1, a[0], n)
		for i := int64(1); i <= m; i++ {
			fmt.Fscan(r, &que)
			ans := int64(0)
			for i := que; i >= 1; i-- {
				sum[i][0], sum[i][1] = sum[i][1], sum[i][0]
			}
			for i := int64(0); i <= n; i++ {
				ans += sum[i][0]
			}
			fmt.Fprintln(w, ans)
		}
	}
	w.Flush()
}

package main

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

var (
	a     []int64 = make([]int64, (1<<20)+1)
	state []int64 = make([]int64, (1<<20)+1)
	aux   []int64 = make([]int64, (1<<20)+1)
	que   []int64 = make([]int64, 1000001)
	sum   int64
)

func Reverse(a []int64, low int64, high int64) {
	for i := low; i <= (low+high)/2; i++ {
		a[i], a[high-i+low] = a[high-i+low], a[i]
	}
}

func LowerBound(a []int64, low, high int64, value int64) int64 {
	l, h := low, high
	pos := high + 1
	for l <= h {
		mid := (l + h) / 2
		if value > a[mid] {
			h = mid - 1
			pos = l
		} else {
			l = mid + 1
		}
	}
	return pos
}

func Merge(a []int64, aux []int64, low int64, mid int64, high int64) {
	for i, j, k := low, mid+1, low; k <= high; k++ {
		if j > high || i <= mid && aux[i] >= aux[j] {
			a[k] = aux[i]
			i++
		} else {
			a[k] = aux[j]
			j++
		}
	}
}

func Inversions(a []int64, aux []int64, low int64, high int64) {
	if low >= high {
		return
	}
	mid := (low + high) / 2
	Inversions(aux, a, low, mid)
	Inversions(aux, a, mid+1, high)
	count := int64(0)
	for i, j := mid, high; i >= low; i-- {
		j = LowerBound(a, mid+1, j, a[i]) - 1
		count += high - j
	}
	sum += count
	if aux[mid] >= aux[mid+1] {
		copy(a[low:high+1], aux[low:high+1])
	} else {
		Merge(a, aux, low, mid, high)
	}
}

func main() {
	var n, m int64
	r := bufio.NewReader(os.Stdin)
	for {
		_, err := fmt.Fscan(r, &n)
		if err == io.EOF {
			break
		}
		length := int64(math.Pow(2, float64(n)))
		a[0] = length
		for i := int64(1); i <= length; i++ {
			fmt.Fscan(r, &a[i])
		}
		fmt.Fscan(r, &m)
		for i := int64(1); i <= m; i++ {
			fmt.Fscan(r, &que[i])
		}
		for i := int64(1); i <= m; i++ {
			sum = int64(0)
			q := int64(math.Pow(2, float64(que[i])))
			for i := int64(1); i <= a[0]; i += q {
				Reverse(a, i, i+q-1)
			}
			copy(state[1:a[0]+1], a[1:a[0]+1])
			copy(aux[1:a[0]+1], a[1:a[0]+1])
			Inversions(a, aux, 1, a[0])
			copy(a[1:a[0]+1], state[1:a[0]+1])
			fmt.Println(sum)
		}
	}
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func printUint64ln(b io.ByteWriter, d uint64) {
	if d == 0 {
		b.WriteByte('0')
		b.WriteByte('\n')
		return
	}
	for d > 0 {
		b.WriteByte(byte(d%10)+'0')
		d /= 10
	}
	b.WriteByte('\n')
	return
}
func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := uint64(0)
        for _, v := range num[:] {
            r += uint64(v[0])
        }
        //fmt.Println(r)
        printUint64ln(out, r)
    }
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}
func main() {
	inp := bufio.NewReader(os.Stdin)
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    if m > 600000 {
    	return
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const MN = 21
const INF = 1<<40
var a, ab [1<<MN]int64
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

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

    var n uint
    fmt.Fscanln(inp, &n)

    s, _ := inp.ReadString('\n')
    s = strings.TrimSpace(s)

    u := strings.Split(s, " ")
    for i, v := range u {
        a[i], _ = strconv.ParseInt(v, 10, 64)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    s, _ = inp.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        q[i], _ = strconv.Atoi(v)
    }
    if m > 60000 {
    	return
    }

    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

import (
	"fmt"
)

const MN = 21
const INF = 1<<29
var a, ab [1<<MN]int
var num [MN]int64
func merge(l, r, k int) {
	if r - l == 1 {
		return
	}
	md := (l+r)/2
	merge(l, md, k-1)
	merge(md, r, k-1)
	l1, l2 := l, md
	d := int64(0)
	for i := l; i < r; i++ {
		var d1, d2 int
		if (l1 < md) {
			d1 = a[l1]
		} else {
			d1 = INF
		}
		if (l2 < r) {
			d2 = a[l2]
		} else {
			d2 = INF
		}
		if (d1 < d2) {
			ab[i] = d1
			l1++
		} else {
			ab[i] = d2
			l2++
			d += int64(md - l1)
		}
	}
	copy(a[l:r], ab[l:r])
	num[k] += d
}

func main() {
	var n uint
	fmt.Scanln(&n)
	for i := 0; i < 1<<n; i++ {
		fmt.Scan(&a[i])
	}
	var m uint
	fmt.Scanln(&m)
	q := make([]uint, m)
	for i := uint(0); i < m; i++ {
		fmt.Scan(&q[i])
	}
	merge(0, 1<<n, int(n));
	for _, p := range q {
		for j := uint(1); j <= p; j++ {
			num[j] = 1<<(n-j) * 1<<((j-1)*2) - num[j]
		}
		r := int64(0)
		for _, v := range num[:] {
			r += v
		}
		fmt.Println(r)
	}
}

package main

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

const MN = 21
const INF = 1<<40
var a, ab [1<<MN]int64
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int64
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

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

    var n uint
    fmt.Fscanln(inp, &n)

    s, _ := inp.ReadString('\n')
    s = strings.TrimSpace(s)

    u := strings.Split(s, " ")
    for i, v := range u {
        a[i], _ = strconv.ParseInt(v, 10, 64)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    s, _ = inp.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        q[i], _ = strconv.Atoi(v)
    }
    if n >= 18 {
    	return
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const MN = 21
const INF = 1e9+100
var a, ab [1<<MN]int
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}

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

    var n uint
    fmt.Fscanln(inp, &n)

    s, _ := inp.ReadString('\n')
    s = strings.TrimSpace(s)

    u := strings.Split(s, " ")
    for i, v := range u {
        a[i], _ = strconv.Atoi(v)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    s, _ = inp.ReadString('\n')
    s = strings.TrimSpace(s)
    u = strings.Split(s, " ")
    for i, v := range u {
        q[i], _ = strconv.Atoi(v)
    }
    if n >= 18 {
    	return
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

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

const MN = 3
const INF = 1e9+100
var a, ab [1<<MN]int
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 int
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getInt(b io.ByteReader) int {
	d := 0
	for {
		c, _ := b.ReadByte()
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += int(c)
		} else {
			return d
		}
	}
}
func main() {
	inp := bufio.NewReader(os.Stdin)
    var n uint
    fmt.Fscanln(inp, &n)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getInt(inp)
    }

    var m uint
    fmt.Fscanln(inp, &m)

    q := make([]int, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getInt(inp)
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := 1; j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := int64(0)
        for _, v := range num[:] {
            r += v[0]
        }
        fmt.Println(r)
    }
}

package main

import (
	"fmt"
)

const MN = 21
const INF = 1<<29
var a, ab [1<<MN]int
var num [MN]int64

func merge(l, r, k int) {
	if r - l == 1 {
		return
	}
	md := (l+r)/2
	merge(l, md, k-1)
	merge(md, r, k-1)
	l1, l2 := l, md
	d := int64(0)
	for i := l; i < r; i++ {
		var d1, d2 int
		if (l1 < md) {
			d1 = a[l1]
		} else {
			d1 = INF
		}
		if (l2 < r) {
			d2 = a[l2]
		} else {
			d2 = INF
		}
		if (d1 < d2) {
			ab[i] = d1
			l1++
		} else {
			ab[i] = d2
			l2++
			d += int64(md - l1)
		}
	}
	copy(a[l:r], ab[l:r])
	num[k] += d
}

func main() {
	var n uint
	fmt.Scan(&n)
	for i := 0; i < 1<<n; i++ {
		fmt.Scan(&a[i])
	}
	var m uint
	fmt.Scan(&m)
	q := make([]uint, m)
	for i := uint(0); i < m; i++ {
		fmt.Scan(&q[i])
	}
	merge(0, 1<<n, int(n));
	for _, p := range q {
		for j := uint(1); j <= p; j++ {
			num[j] = 1<<(n-j) * 1<<((j-1)*2) - num[j]
		}
		r := int64(0)
		for _, v := range num[:] {
			r += v
		}
		fmt.Println(r)
	}
}

package main

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

const MN = 20
const INF = 1e9+100
var a, ab [1<<MN]uint
var num [MN+1][2]int64

func merge(l, r, k int) {
    if r - l == 1 {
        return
    }
    md := (l+r)/2
    merge(l, md, k-1)
    merge(md, r, k-1)
    u1, u2 := int64(0), int64(0)
    l1, l2 := l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 <= d2) {
            ab[i] = d1
            l1++
        } else {
            ab[i] = d2
            l2++
            u1 += int64(md - l1)
        }
    }
    l1, l2 = l, md
    for i := l; i < r; i++ {
        var d1, d2 uint
        if (l1 < md) {
            d1 = a[l1]
        } else {
            d1 = INF
        }
        if (l2 < r) {
            d2 = a[l2]
        } else {
            d2 = INF
        }
        if (d1 < d2) {
            l1++
            u2 += int64(r - l2)
        } else {
            l2++
        }
    }
    copy(a[l:r], ab[l:r])
    num[k][0] += u1
    num[k][1] += u2

}
func getUint(b io.ByteReader) uint {
	d := uint(0)
	var c byte
	for {
		c, _ = b.ReadByte()
		if (c != ' ' && c != '\n'){
			break
		}
	}
	for {
		c -= '0'
		if 0 <= c && c <= 9 {
			d *= 10
			d += uint(c)
		} else {
			return d
		}
		c, _ = b.ReadByte()
	}
}

func printUint64ln(b io.ByteWriter, d uint64) {
	if d == 0 {
		b.WriteByte('0')
		b.WriteByte('\n')
		return
	}
	for d > 0 {
		b.WriteByte(byte(d%10)+'0')
		d /= 10
	}
	b.WriteByte('\n')
	return
}
func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
    var n uint
    n = getUint(inp)
    for i := uint(0); i < 1<<n; i++ {
    	a[i] = getUint(inp)
    }

    var m uint
    m = getUint(inp)
    q := make([]uint, m)
    for i := uint(0); i < m; i++ {
    	q[i] = getUint(inp)
    }
    if m > 600000 {
    	return
    }
    merge(0, 1<<n, int(n));
    for _, p := range q {
        for j := uint(1); j <= p; j++ {
            e := num[j][0]
            num[j][0] = num[j][1]
            num[j][1] = e
        }
        r := uint64(0)
        for _, v := range num[:] {
            r += uint64(v[0])
        }
        //fmt.Println(r)
        printUint64ln(out, r)
    }
}

package main

import (
	"fmt"
)

const MN = 21
const INF = 1<<40
var a, ab [1<<MN]int64
var num [MN+1][2]int64

func merge(l, r, k int) {
	if r - l == 1 {
		return
	}
	md := (l+r)/2
	merge(l, md, k-1)
	merge(md, r, k-1)
	u1, u2 := int64(0), int64(0)
	l1, l2 := l, md
	for i := l; i < r; i++ {
		var d1, d2 int64
		if (l1 < md) {
			d1 = a[l1]
		} else {
			d1 = INF
		}
		if (l2 < r) {
			d2 = a[l2]
		} else {
			d2 = INF
		}
		if (d1 <= d2) {
			ab[i] = d1
			l1++
		} else {
			ab[i] = d2
			l2++
			u1 += int64(md - l1)
		}
	}
	l1, l2 = l, md
	for i := l; i < r; i++ {
		var d1, d2 int64
		if (l1 < md) {
			d1 = a[l1]
		} else {
			d1 = INF
		}
		if (l2 < r) {
			d2 = a[l2]
		} else {
			d2 = INF
		}
		if (d1 < d2) {
			l1++
			u2 += int64(r - l2)
		} else {
			l2++
		}
	}
	copy(a[l:r], ab[l:r])
	num[k][0] += u1
	num[k][1] += u2

}

func main() {
	var n uint
	fmt.Scan(&n)
	for i := 0; i < 1<<n; i++ {
		fmt.Scan(&a[i])
	}
	var m uint
	fmt.Scan(&m)
	q := make([]uint, m)
	for i := uint(0); i < m; i++ {
		fmt.Scan(&q[i])
	}
	if m > 600000 {
		return
	}
	merge(0, 1<<n, int(n));
	for _, p := range q {
		for j := uint(1); j <= p; j++ {
			e := num[j][0]
			num[j][0] = num[j][1]
			num[j][1] = e
		}
		r := int64(0)
		for _, v := range num[:] {
			r += v[0]
		}
		fmt.Println(r)
	}
}


package main

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

const Inf = int(1e9)

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

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

	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &a[i])
	}

	fmt.Println(shortestCycle(a))
}

func isOn(n int64, b uint) bool {
	return (n & (1 << b)) != 0
}

func shortestCycle(a []int64) int {
	bIdx := make(map[uint][]int64)
	for _, e := range a {
		for b := uint(0); b < 64; b++ {
			if isOn(e, b) {
				bIdx[b] = append(bIdx[b], e)
			}
		}
	}

	g := make(map[int64][]int64)
	for _, ar := range bIdx {
		if len(ar) >= 3 {
			return 3
		}
		for i := 0; i < len(ar); i++ {
			for j := i + 1; j < len(ar); j++ {
				u, v := ar[i], ar[j]
				g[u] = append(g[u], v)
				g[v] = append(g[v], u)
			}
		}
	}

	minCycle := Inf
	for _, r := range a {
		seen := make(map[int64]bool)
		lv := make(map[int64]int)
		for _, ch := range g[r] {
			if !seen[ch] {
				minCycle = min(minCycle, dfs(r, ch, r, g, seen, lv)+1)
			}
		}
	}

	if minCycle >= Inf {
		return -1
	}

	return minCycle
}

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

func dfs(top, r, par int64, g map[int64][]int64, seen map[int64]bool, d map[int64]int) int {
	seen[r] = true
	d[r] = Inf
	for _, v := range g[r] {
		if v == par {
			continue
		} else if v == top {
			d[r] = 1
		} else if seen[v] {
			d[r] = min(d[r], 1+d[v])
		} else {
			d[r] = min(d[r], 1+dfs(top, v, r, g, seen, d))
		}
	}
	return d[r]
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1205B(reader io.Reader, writer io.Writer) {
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	const inf int = 1e8

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

	var n int
	Fscan(in, &n)
	arr := make([]int64, n)
	bitIndexes := make([][]int, 60)
	for i := 0; i < n; i++ {
		var a int64
		Fscan(in, &a)
		arr[i] = a
		for j := 0; a > 0; j++ {
			if a&1 == 1 {
				bitIndexes[j] = append(bitIndexes[j], i)
			}
			a >>= 1
		}
	}

	uniqueSet := map[int64]int{}
	for _, indexes := range bitIndexes {
		if len(indexes) >= 3 {
			Fprintln(out, 3)
			return
		}
		for _, idx := range indexes {
			uniqueSet[arr[idx]] = 1
		}
	}
	uniqueArr := []int64{}
	for k := range uniqueSet {
		uniqueArr = append(uniqueArr, k)
	}

	// 剩下不超过120个数，暴力求最小环即可
	sz := len(uniqueArr)
	weights := make([][]int, sz)
	for i := range weights {
		weights[i] = make([]int, sz)
		for j := range weights[i] {
			weights[i][j] = inf
		}
	}
	for i := range weights {
		weights[i][i] = 0
	}
	for i, ai := range uniqueArr {
		for j := i + 1; j < sz; j++ {
			if ai&uniqueArr[j] > 0 {
				weights[i][j] = 1
				weights[j][i] = 1
			}
		}
	}
	dist := make([][]int, sz)
	for i := range dist {
		dist[i] = make([]int, sz)
		copy(dist[i], weights[i])
	}
	ans := inf
	for k := 0; k < sz; k++ {
		for i := 0; i < k; i++ {
			for j := 0; j < i; j++ {
				ans = min(ans, dist[i][j]+weights[i][k]+weights[k][j])
			}
		}
		for i := 0; i < sz; i++ {
			for j := 0; j < sz; j++ {
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
			}
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(out, ans)
}

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

// Author: sighduck
// URL: https://codeforces.com/contest/1205/problem/B

package main

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

type QueueItem struct {
	Index      int
	PathLength int
}

func createAdjacencyMatrix(n int, a []int64) [][]bool {
	matrix := make([][]bool, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]bool, n)
	}
	b := []int64{}
	for _, elem := range a {
		if elem != 0 {
			b = append(b, elem)
		}
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if b[i]&b[j] > 0 {
				matrix[i][j] = true
				matrix[j][i] = true
			}
		}
	}
	return matrix
}

func getMinCycleLength(n int, matrix [][]bool, i int) int {
	queue := []QueueItem{QueueItem{Index: i, PathLength: 1}}
	pathLengthMap := make(map[int]int)
	for len(queue) > 0 {
		var current QueueItem
		current, queue = queue[0], queue[1:]
		if pathLengthMap[current.Index] > 0 {
			return current.PathLength + pathLengthMap[current.Index] - 2
		}
		pathLengthMap[current.Index] = current.PathLength
		for i := 0; i < n; i++ {
			if i != current.Index && matrix[i][current.Index] && pathLengthMap[i] == 0 {
				queue = append(queue, QueueItem{Index: i, PathLength: current.PathLength + 1})
			}
		}
	}
	return 0
}

func search(n int, matrix [][]bool) int {
	pathLengthMap := make(map[int]int)
	cycleExists := false
	minCycleLength := n + 1
	for i := 0; i < n; i++ {
		if pathLengthMap[i] == 0 {
			length := getMinCycleLength(n, matrix, i)
			if length > 0 && length < minCycleLength {
				minCycleLength = length
				cycleExists = true
			}
		}
	}
	if !cycleExists {
		return -1
	}
	return minCycleLength
}

func Solve(n int, a []int64) int {
	nonZeroNodes := 0
	for _, elem := range a {
		if elem != 0 {
			nonZeroNodes += 1
		}
	}
	if nonZeroNodes >= 121 {
		return 3
	}
	matrix := createAdjacencyMatrix(nonZeroNodes, a)
	return search(nonZeroNodes, matrix)
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1205B(reader io.Reader, writer io.Writer) {
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	const inf int = 1e9

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

	var n int
	Fscan(in, &n)
	arr := make([]int64, n)
	bitIndexes := make([][]int, 60)
	for i := 0; i < n; i++ {
		var a int64
		Fscan(in, &a)
		arr[i] = a
		for j := 0; a > 0; j++ {
			if a&1 == 1 {
				bitIndexes[j] = append(bitIndexes[j], i)
			}
			a >>= 1
		}
	}

	uniqueSet := map[int64]int{}
	for _, indexes := range bitIndexes {
		if len(indexes) >= 3 {
			Fprintln(out, 3)
			return
		}
		for _, idx := range indexes {
			uniqueSet[arr[idx]] = 1
		}
	}
	uniqueArr := []int64{}
	for k := range uniqueSet {
		uniqueArr = append(uniqueArr, k)
	}

	// 剩下不超过120个数，暴力求最小环即可
	sz := len(uniqueArr)
	weights := make([][]int, sz)
	for i := range weights {
		weights[i] = make([]int, sz)
		for j := range weights[i] {
			weights[i][j] = inf
		}
	}
	for i := range weights {
		weights[i][i] = 0
	}
	for i, ai := range uniqueArr {
		for j := i + 1; j < sz; j++ {
			if ai&uniqueArr[j] > 0 {
				weights[i][j] = 1
				weights[j][i] = 1
			}
		}
	}
	dist := make([][]int, sz)
	for i := range dist {
		dist[i] = make([]int, sz)
		copy(dist[i], weights[i])
	}
	ans := inf
	for k := 0; k < sz; k++ {
		for i := 0; i < k; i++ {
			for j := 0; j < i; j++ {
				ans = min(ans, dist[i][j]+weights[i][k]+weights[k][j])
			}
		}
		for i := 0; i < sz; i++ {
			for j := 0; j < sz; j++ {
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
			}
		}
	}
	if ans == inf || ans < 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1205B(reader io.Reader, writer io.Writer) {
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	const inf int = 1e9

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

	var n int
	Fscan(in, &n)
	arr := make([]int64, n)
	bitIndexes := make([][]int, 60)
	for i := 0; i < n; i++ {
		var a int64
		Fscan(in, &a)
		arr[i] = a
		for j := 0; a > 0; j++ {
			if a&1 == 1 {
				bitIndexes[j] = append(bitIndexes[j], i)
			}
			a >>= 1
		}
	}

	uniqueSet := map[int64]int{}
	for _, indexes := range bitIndexes {
		if len(indexes) >= 3 {
			Fprintln(out, 3)
			return
		}
		for _, idx := range indexes {
			uniqueSet[arr[idx]] = 1
		}
	}
	uniqueArr := []int64{}
	for k := range uniqueSet {
		uniqueArr = append(uniqueArr, k)
	}

	// 剩下不超过120个数，暴力求最小环即可
	sz := len(uniqueArr)
	weights := make([][]int, sz)
	for i := range weights {
		weights[i] = make([]int, sz)
		for j := range weights[i] {
			weights[i][j] = inf
		}
	}
	for i := range weights {
		weights[i][i] = 0
	}
	for i, ai := range uniqueArr {
		for j := i + 1; j < sz; j++ {
			if ai&uniqueArr[j] > 0 {
				weights[i][j] = 1
				weights[j][i] = 1
			}
		}
	}
	dist := make([][]int, sz)
	for i := range dist {
		dist[i] = make([]int, sz)
		copy(dist[i], weights[i])
	}
	ans := inf
	for k := 0; k < sz; k++ {
		for i := 0; i < k; i++ {
			for j := 0; j < i; j++ {
				ans = min(ans, dist[i][j]+weights[i][k]+weights[k][j])
			}
		}
		for i := 0; i < sz; i++ {
			for j := 0; j < sz; j++ {
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
			}
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(out, ans)
}

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

// Author: sighduck
// URL: https://codeforces.com/contest/1205/problem/B

package main

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

type QueueItem struct {
	Index      int
	PathLength int
}

func createAdjacencyMatrix(n int, a []int64) [][]bool {
	matrix := make([][]bool, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]bool, n)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i]&a[j] > 0 {
				matrix[i][j] = true
				matrix[j][i] = true
			}
		}
	}
	return matrix
}

func getMinCycleLength(n int, pathLengthMap map[int]int, matrix [][]bool, i int) (map[int]int, int) {
	queue := []QueueItem{QueueItem{Index: i, PathLength: 1}}
	for len(queue) > 0 {
		var current QueueItem
		current, queue = queue[0], queue[1:]
		if pathLengthMap[current.Index] > 0 {
			return pathLengthMap, current.PathLength + pathLengthMap[current.Index] - 2
		}
		pathLengthMap[current.Index] = current.PathLength
		for i := 0; i < n; i++ {
			if i != current.Index && matrix[i][current.Index] && pathLengthMap[i] == 0 {
				queue = append(queue, QueueItem{Index: i, PathLength: current.PathLength + 1})
			}
		}
	}
	return pathLengthMap, 0
}

func search(n int, matrix [][]bool) int {
	pathLengthMap := make(map[int]int)
	cycleExists := false
	minCycleLength := n + 1
	for i := 0; i < n; i++ {
		if pathLengthMap[i] == 0 {
			var length int
			pathLengthMap, length = getMinCycleLength(n, pathLengthMap, matrix, i)
			if length > 0 && length < minCycleLength {
				minCycleLength = length
				cycleExists = true
			}
		}
	}
	if !cycleExists {
		return -1
	}
	return minCycleLength
}

func Solve(n int, a []int64) int {
	nonZeroNodes := 0
	for _, elem := range a {
		if elem != 0 {
			nonZeroNodes += 1
		}
	}
	if nonZeroNodes >= 121 {
		return 3
	}
	matrix := createAdjacencyMatrix(n, a)
	return search(n, matrix)
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1205/problem/B

package main

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

type QueueItem struct {
	Index      int
	PathLength int
}

func createAdjacencyMatrix(n int, a []int64) [][]bool {
	adj := make([][]bool, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]bool, n)
	}
	for i := 0; i < n; i++ {
		for j := 1; j < n; j++ {
			if a[i]&a[j] > 0 {
				adj[i][j] = true
				adj[j][i] = true
			}
		}
	}
	return adj
}

func Solve(n int, a []int64) int {
	nonZeroNodes := 0
	for _, elem := range a {
		if elem != 0 {
			nonZeroNodes += 1
		}
	}
	if nonZeroNodes >= 121 {
		return 3
	}
	adj := createAdjacencyMatrix(n, a)
	queue := []QueueItem{QueueItem{Index: 0, PathLength: 1}}
	pathLength := make(map[int]int)
	for len(queue) > 0 {
		var current QueueItem
		current, queue = queue[0], queue[1:]
		if pathLength[current.Index] > 0 {
			return current.PathLength + pathLength[current.Index] - 2
		}
		pathLength[current.Index] = current.PathLength
		for i := 0; i < n; i++ {
			if i != current.Index && adj[i][current.Index] && pathLength[i] == 0 {
				queue = append(queue, QueueItem{Index: i, PathLength: current.PathLength + 1})
			}
		}
	}
	return -1
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}


package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i:= 0 ; i< t; i++{
		var p, h string
		var ans int
		fmt.Scanln(&p)
		fmt.Scanln(&h)
		target := make([]int, 26)
		for j := 0; j < len(p); j++{
			target[p[j] - 'a']++
			ans++
		}
		if len(h) < len(p){
			fmt.Println("NO")
			continue
		}
		tar1 := make([]int, 26)
		copy(tar1, target)
		ans1 := ans
		var found bool
		var startAt int
		for k:= 0; k < len(h); {
			if tar1[h[k] - 'a'] == 0{
				ans1 = ans
				copy(tar1, target)
				startAt++
				k = startAt
			}else{
				tar1[h[k] - 'a']--
				ans1--
				k++
				if ans1 ==0{
					found = true
					break
				}
			}
		}
		if found{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		s := ""
		ss := ""
		fmt.Fscanf(in, "%s\n", &s)
		fmt.Fscanf(in, "%s\n", &ss)
		ok := false
		length := len(ss)
		for i := 0; i < length; i++ {
			//fmt.Println(ss)
			if len(ss) < len(s) {
				break
			}
			sub := ss[:len(s)]
			if same(s, sub) {
				//fmt.Println(s, sub)
				ok = true
				break
			}
			ss = ss[1:]
		}
		if ok {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	return
}
func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var p, h string
		fmt.Scanf("%s\n", &p)
		fmt.Scanf("%s\n", &h)

		pMap := make(map[uint8]int)
		hMap := make(map[uint8]int)

		for ch := uint8('a'); ch <= 'z'; ch++ {
			pMap[ch] = 0
			hMap[ch] = 0
		}

		for j := 0; j < len(p); j++ {
			pMap[p[j]]++
		}

		yes := false
		for j := 0; j <= len(h)-len(p); j++ {
			if j == 0 {
				for k := 0; k < len(p); k++ {
					hMap[h[k]]++
				}
			} else {
				hMap[h[j-1]]--
				hMap[h[j+len(p)-1]]++
			}

			currYes := true
			for k, v := range pMap {
				if hMap[k] != v {
					currYes = false
					break
				}
			}
			if currYes {
				yes = true
				break
			}
		}
		if yes {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

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

var t int
var P, H []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		P, H = ReadRuneSlice(), ReadRuneSlice()

		solve()
	}
}

func solve() {
	if len(P) > len(H) {
		fmt.Println("NO")
		return
	}

	pL := RuneList{}
	for i := 0; i < len(P); i++ {
		pL = append(pL, P[i])
	}
	sort.Sort(pL)

	plen := len(P)
	for i := 0; i < len(H); i++ {
		if i+plen > len(H) {
			break
		}

		tmp := H[i : i+plen]
		hL := RuneList{}
		for j := 0; j < len(tmp); j++ {
			hL = append(hL, tmp[j])
		}
		sort.Sort(hL)

		if string(pL) == string(hL) {
			fmt.Println("YES")
			return
		}
	}

	fmt.Println("NO")
}

type RuneList []rune

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

// S := RuneList{'a', 'b', 'c'}
// sort.Sort(S) or sort.Sort(sort.Reverse(S))

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
	- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T int
	var s, t []byte
	O := [26]int{}
o:
	for Scan(&T); T > 0; T-- {
		Scan(&s, &t)
		if len(t) < len(s) {
			Println("NO")
			continue
		}
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		for _, b := range t[:len(s)] {
			cnt[b-'a']--
		}
		if cnt == O {
			Println("YES")
			continue
		}
		for i, b := range t[len(s):] {
			cnt[t[i]-'a']++
			cnt[b-'a']--
			if cnt == O {
				Println("YES")
				continue o
			}
		}
		Println("NO")
	}
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var (
		t uint
		channels []chan bool
	)

	for fmt.Scanln(&t); t > 0; t-- {
		// Declaration inside the for block necessary to avoid races.
		var p, h string

		fmt.Scanln(&p)
		fmt.Scanln(&h)

		ch := make(chan bool)
		channels = append(channels, ch)
		go func() {
			ch <- solve(p, h)
		}()
	}

	for _, ch := range channels {
		if <-ch {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z' - 'a' + 1]uint
	for _, c := range p {
		pms[c-'a']++
	}
	for _, c := range h[:len(p)] {
		hms[c-'a']++
	}

	if pms == hms {
		return true
	}

	for i := 0; i < len(h)-len(p); i++ {
		hms[h[i]-'a']--
		hms[h[i+len(p)]-'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanln(&t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanln(&p)
		fmt.Scanln(&h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	if pms == hms {
		return true
	}

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanln(&t)

	var channels []chan bool

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanln(&p)
		fmt.Scanln(&h)

		ch := make(chan bool)
		channels = append(channels, ch)
		go func() {
			ch <- solve(p, h)
		}()
	}

	for _, ch := range channels {
		if <-ch {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z' - 'a' + 1]uint
	for _, c := range p {
		pms[c-'a']++
	}
	for _, c := range h[:len(p)] {
		hms[c-'a']++
	}

	if pms == hms {
		return true
	}

	for i := 0; i < len(h)-len(p); i++ {
		hms[h[i]-'a']--
		hms[h[i+len(p)]-'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanln(&t)

	var channels []chan bool

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanln(&p)
		fmt.Scanln(&h)

		ch := make(chan bool)
		channels = append(channels, ch)
		go func() {
			ch <- solve(p, h)
		}()
	}

	for _, ch := range channels {
		if <-ch {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	if pms == hms {
		return true
	}

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

package main

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

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

	var numTestCases int
	var passwd, hash string
	fmt.Fscanf(reader, "%d\n", &numTestCases)

	for tcase := 1; tcase <= numTestCases; tcase++ {

		fmt.Fscanf(reader, "%s\n", &passwd)
		fmt.Fscanf(reader, "%s\n", &hash)
		pLen := len(passwd)
		hLen := len(hash)
		countByPCh := make(map[byte]int)
		for _, b := range []byte(passwd) {
			if _, ok := countByPCh[b]; !ok {
				countByPCh[b] = 1
			} else {
				countByPCh[b] += 1
			}
		}
		var found bool
		for i := 0; i <= hLen-pLen; i++ {
			found = true
			countByHCh := make(map[byte]int)
			for _, b := range []byte(hash[i : i+pLen]) {
				if _, ok := countByHCh[b]; !ok {
					countByHCh[b] = 1
				} else {
					countByHCh[b] += 1
				}
			}
			for b, count := range countByHCh {
				if count1, ok := countByPCh[b]; ok {
					if count != count1 {
						found = false
						break
					}
				} else {
					found = false
					break
				}
			}
			if found {
				break
			}
		}
		if found {
			fmt.Fprintf(writer, "YES\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		s := ""
		ss := ""
		fmt.Fscanf(in, "%s\n", &s)
		fmt.Fscanf(in, "%s\n", &ss)
		ok := false
		for i := 0; i < len(ss); i++ {
			if len(ss) < len(s) {
				break
			}
			sub := ss[:len(s)]
			if same(s, sub) {
				//fmt.Println(s, sub)
				ok = true
				break
			}
			ss = ss[1:]
		}
		if ok {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	return
}
func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i:= 0 ; i< t; i++{
		var p, h string
		var ans int
		fmt.Scanln(&p)
		fmt.Scanln(&h)
		target := make([]int, 26)
		for j := 0; j < len(p); j++{
			target[p[j] - 'a']++
			ans++
		}
		if len(h) < len(p){
			fmt.Println("NO")
		}
		tar1 := make([]int, 26)
		copy(tar1, target)
		ans1 := ans
		var found bool
		var startAt int
		for k:= 0; k < len(h); {
			if tar1[h[k] - 'a'] == 0{
				ans1 = ans
				copy(tar1, target)
				startAt++
				k = startAt
			}else{
				tar1[h[k] - 'a']--
				ans1--
				k++
				if ans1 ==0{
					found = true
					break
				}
			}
		}
		if found{
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanf("%s", &p)
		fmt.Scanf("%s", &h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	if pms == hms {
		return true
	}

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanln(&p)
		fmt.Scanln(&h)

		fmt.Println(p); fmt.Println(h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	if pms == hms {
		return true
	}

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		if pms == hms {
			return true
		}
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanf("%s", &p)
		fmt.Scanf("%s", &h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	fmt.Println(0)

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	fmt.Println(1)

	if pms == hms {
		fmt.Println(pms); fmt.Println(hms)
		return true
	}

	fmt.Println(2)

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		fmt.Println(3)

		if pms == hms {
			fmt.Println(pms); fmt.Println(hms)
			return true
		}

		fmt.Println(4)
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanf("%s", &p)
		fmt.Scanf("%s", &h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanf("%s", &p)
		fmt.Scanf("%s", &h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	fmt.Println(0)

	var pms, hms ['z'-'a'+1]uint
	fmt.Println(p)
	for _, c := range p {
		fmt.Println(c)
		pms[c - 'a']++
	}
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	fmt.Println(1)

	if pms == hms {
		fmt.Println(pms); fmt.Println(hms)
		return true
	}

	fmt.Println(2)

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		fmt.Println(3)

		if pms == hms {
			fmt.Println(pms); fmt.Println(hms)
			return true
		}

		fmt.Println(4)
	}

	return false
}

/*
https://codeforces.com/contest/1278/problem/A
https://github.com/miloszlakomy/competitive/tree/master/codeforces/1278A
*/

package main

import (
	"fmt"
)

func main() {
	var t uint
	fmt.Scanf("%d", &t)

	for ; t > 0; t-- {
		var p, h string
		fmt.Scanln(&p)
		fmt.Scanln(&h)

		if solve(p, h) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(p, h string) bool {
	if len(h) < len(p) {
		return false
	}

	var pms, hms ['z'-'a'+1]uint
	for _, c := range p { pms[c - 'a']++ }
	for _, c := range h[:len(p)] { hms[c - 'a']++ }

	if pms == hms {
		return true
	}

	for i := 0; i < len(h) - len(p); i++ {
		hms[h[i] - 'a']--
		hms[h[i+len(p)] - 'a']++

		if pms == hms {
			return true
		}
	}

	return false
}


package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var y,k,n int
    fmt.Scan(&y,&k,&n)
    first := true
    for i := ((y/k)+1)*k; i <= n; i += k {
        if first { first = false } else { writer.WriteRune(' ') }
        writer.WriteString(strconv.Itoa(i-y))
    }
    if first { writer.WriteString("-1") }
    writer.WriteRune('\n')
    writer.Flush()
}

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

func main() {
	var n,k,y,j int
	b:=0
	fmt.Scan(&y,&k,&n)
	j=k-y%k
	for ;j<=n-y; {
		fmt.Print(j," ")
		j+=k
		b++
	}
	if b==0 {
		fmt.Println("-1")
	}

}

// 239A-mic
package main

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

func main() {
    w := bufio.NewWriter(os.Stdout)
    var y, k, n int
    fmt.Scan(&y, &k, &n)
    f := false
    for i := k - y%k; i <= n-y; i += k {
        w.WriteString(strconv.Itoa(i))
        f = true
        if i < n {
            w.WriteRune(' ')
        }
    }
    if !f {
        fmt.Print("-1")
    }
    w.WriteRune('\n')
    w.Flush()
}

package main

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

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

	var y, k, n int
	Fscan(in, &y)
	Fscan(in, &k)
	Fscan(in, &n)

	for i := (y/k + 1) * k; i <= n; i += k {
		Fprintln(out, i-y)
	}

	if (y/k+1)*k > n {
		Fprintln(out, -1)
	}

}

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


package main

import (
	"fmt"
	"os"
)

func main() {
	var numberOfTests int
	//testData := "5\nrb\nbr\ncc\nwb\naa\naa\nab\ncd\nyy\nxx"
	//reader := strings.NewReader(testData)
	reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(len(m) - 1)
	}
}

package main

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

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

	for t > 0 {
		t--
		s := make([]int, 26, 26)
		for _, c := range readLine(in) {
			s[int(c-'a')]++
		}
		for _, c := range readLine(in) {
			s[int(c-'a')]++
		}
		ret := 0
		for _, v := range s {
			if v > 0 {
				ret++
			}
		}
		fmt.Println(ret - 1)
	}
}

///////////////////////////////////
// DO NOT EDIT
///////////////////////////////////

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

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

func readLineNumbs(in *bufio.Reader) []string {
	numbs := strings.Split(readLine(in), " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

var P107 int = 1000000007

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

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

func Abs(a int) int {
	return Max(a, -a)
}

func Gcd(a, b int) int {
	min := Min(a, b)
	max := Max(a, b)
	if min == 0 {
		return max
	}

	for max%min != 0 {
		min, max = max%min, min
	}

	return min
}

func Lcm(a, b int) int {
	return a / Gcd(a, b) * b
}

// var facs []int = make([]int, X + 1)
func FacP(n, p int) int {
  // if facs[n] != 0 {
  //   return facs[n]
  // }
	result := 1
  // facs[0] = 1
	for i := 1; i <= n; i++ {
		result = (result * i) % p
    // facs[i] = result
	}

	return result
}

func ExpP(a, x, p int) int {
	if x == 0 {
		return 1
	}

	if x%2 == 0 {
		half := ExpP(a, x/2, p)
		return (half * half) % p
	} else {
		return ((a % p) * ExpP(a, x-1, p)) % p
	}
}

func CombP(n, c, p int) int {
  // If CombP be called multiple times, you should optimize FacP using memoization.
	return (FacP(n, p) * ((ExpP(FacP(n-c, p), p-2, p) * ExpP(FacP(c, p), p-2, p)) % p)) % p
}

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

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

  for _i := 0; _i < t; _i++ {
    scanner.Scan()
    a := []rune(scanner.Text())
    scanner.Scan()
    b := []rune(scanner.Text())
    aph := make([]bool, 26)

    same := 0
    for i := 0; i < 2; i++ {
      if aph[a[i] - 97] {
        same++
      } else {
        aph[a[i] - 97] = true
      }
      if aph[b[i] - 97] {
        same++
      } else {
        aph[b[i] - 97] = true
      }
    }

    wr.WriteString(strconv.Itoa(3 - same) + "\n")
  }
}

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

package main

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

func main() {
	r := readerStdin()

	for cases := readInt(r); cases != 0; cases-- {
		var image = make([]byte, 0, 4)
		for i := 0; i < 2; i++ {
			image = append(image, []byte(readString(r))...)
		}

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

		var countQuantity int
		for i := 0; i < len(image)-1; i++ {
			if image[i] != image[i+1] {
				countQuantity++
			}
		}
		fmt.Println(countQuantity)
	}
}

func readerStdin() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

func readString(r *bufio.Reader) (s string) {
	s, _ = r.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return
}

func readSliceInt(r *bufio.Reader) []int {
	str := readString(r)
	slice := strings.Split(str, " ")

	var result = make([]int, len(slice))
	for i, v := range slice {
		x, _ := strconv.Atoi(v)
		result[i] = x
	}

	return result
}

func readInt(r *bufio.Reader) (i int) {
	str := readString(r)
	i, _ = strconv.Atoi(str)
	return
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		myslice := []string{}
		for j := 0; j < 2; j++ {
			var temp string
			fmt.Scan(&temp)
			myslice = append(myslice, temp)
		}
		m1 := make(map[byte]int)
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				char := myslice[j][k]
				m1[char]++
			}

		}
		fmt.Println(len(m1) - 1)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t_ := scanner.Text()
	for t, _ := strconv.Atoi(t_); t > 0; t-- {
		var tm map[rune]bool = make(map[rune] bool)
		for i := 0; i < 2; i++ {
		    scanner.Scan()
			for _, c := range scanner.Text() {
				tm[c] = true
			}
		}
		fmt.Println(len(tm) - 1)
	}
}

package main

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

var in *bufio.Reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscanln(in, &t)
	for t > 0 {
		mp := map[byte]int{}
		for row := 0; row < 2; row++ {
			var s string
			fmt.Fscanln(in, &s)
			for i := range s {
				mp[s[i]]++
			}
		}
		max1, max2 := 0, 0
		for _, v := range mp {
			if max1 < v {
				max2, max1 = max1, v
			} else if max2 < v {
				max2 = v
			}
		}
		if max1 == 4 {
			fmt.Println(0)
		} else if max1 == 3 {
			fmt.Println(1)
		} else if max1 == 2 {
			if max2 == 1 {
				fmt.Println(2)
			} else {
				fmt.Println(1)
			}
		} else {
			fmt.Println(3)
		}
		t--
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	p, q   string
)

func solve(p, q string) int {
	var f = make(map[rune]int)
	for _, x := range p {
		f[x]++
	}
	for _, x := range q {
		f[x]++
	}
	return len(f) - 1
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &p, &q)
		fmt.Println(solve(p, q))
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		s1 := readLineNumbs(input)
		s2 := readLineNumbs(input)
		c := []rune(s1[0])
		tmp := []rune(s2[0])
		c = append(c, tmp[0])
		c = append(c, tmp[1])
		fmt.Println(solve(c))
	}
}

func solve(s []rune) int {
	a := []int{}
	for i := 0; i < 256; i++ {
		a = append(a, 0)
	}
	for i := 0; i < 4; i++ {
		a[int(s[i])]++
	}
	sort.Ints(a)
	tmp := 0
	for i := 0; i < 256; i++ {
		if a[i] > 0 {
			tmp++
		}
	}
	return tmp - 1
}

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

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

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

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main
import (
    "fmt"
)

func work(n string) int {
    u := map[rune]bool{}
    for _, c := range n {
        u[c] = true
    }
    return len(u)-1
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var a, b string
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)
            a += b

            fmt.Printf("%d\n", work(a))
        }
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		aa := make([]int, 26)
		aa[s1[0]-'a']++
		aa[s1[1]-'a']++
		aa[s2[0]-'a']++
		aa[s2[1]-'a']++

		g := max(aa[s1[0]-'a'], aa[s1[1]-'a'], aa[s2[0]-'a'], aa[s2[1]-'a'])
		if g == 4 {
			fmt.Fprintln(out, 0)
		} else if g == 3 {
			fmt.Fprintln(out, 1)
		} else if g == 1 {
			fmt.Fprintln(out, 3)
		} else {
			if aa[s1[0]-'a'] == 2 && aa[s1[1]-'a'] == 2 && aa[s2[0]-'a'] == 2 && aa[s2[1]-'a'] == 2 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 2)
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1721A
Date: 8/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1721/A
Problem: CF1721A
**/
func (in *CF1721A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		mapa := make(map[uint8]bool)
		str := in.NextString()
		mapa[str[0]] = true
		mapa[str[1]] = true
		str = in.NextString()
		mapa[str[0]] = true
		mapa[str[1]] = true
		if len(mapa) == 1 {
			fmt.Println(0)
		} else if len(mapa) == 2 {
			fmt.Println(1)
		} else if len(mapa) == 3 {
			fmt.Println(2)
		} else {
			fmt.Println(3)
		}
	}
}

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

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

package main

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

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

func qwq() {
	var s1, s2 string
	ht := map[byte]int{}
	fmt.Fscan(in, &s1, &s2)
	ht[s1[0]]++
	ht[s1[1]]++
	ht[s2[0]]++
	ht[s2[1]]++
	fmt.Fprintln(out, len(ht)-1)
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b string
		fmt.Fscan(in,&a,&b)
		a+=b
		pairs:=0
		mapper:= make(map[string]bool)
		for j:=0;j<4;j++{
			if mapper[string(a[j])] == true {
				pairs++
				continue
			}
			mapper[string(a[j])]= true
		}
		if pairs == 3 {
			fmt.Fprintln(out,0)
		} else if pairs == 2 {
			fmt.Fprintln(out,1)
		} else if pairs == 1 {
			fmt.Fprintln(out,2)
		} else {
			fmt.Fprintln(out,3)
		}
	}
}

package main

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

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

	var t, cnt int
	for fmt.Fscan(r, &t); t > 0; t-- {
		s := make([]string, 2)
		m := make(map[byte]bool)
		cnt = -1

		for i := 0; i < 2; i++ {
			fmt.Fscan(r, &s[i])
			for j := 0; j < 2; j++ {
				e := s[i][j]
				if _, v := m[e]; !v {
					cnt++
					m[e] = true
				}
			}
		}

		fmt.Fprintln(w, cnt)
	}
}

package main

import (
    "fmt"
    "sort"
    "strings"
)

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

    for i := 0; i < n; i++ {
        var a, b string

        fmt.Scanf("%s\n%s\n",&a,&b)

        c := strings.Split(a + b, "")
        sort.Strings(c)

        ans := 0;
        for j := 1; j < 4; j++ {
            if (c[j] == c[j-1]) {
                continue
            }
            ans++
        }

        fmt.Println(ans)
    }
}

package main
import (
    "fmt"
)

func work(n string) int {
    u := map[rune]bool{}
    for _, c := range n {
        u[c] = true
    }
    return len(u)
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var a, b string
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)
            a += b

            fmt.Printf("%d\n", work(a))
        }
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var numberOfTests int
	reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(4 - len(m))
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var numberOfTests int
	testData := "5\nrb\nbr\ncc\nwb\naa\naa\nab\ncd\nyy\nxx\n"
	reader := strings.NewReader(testData)
	//reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(4 - len(m))
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		aa := make([]int, 26)
		aa[s1[0]-'a']++
		aa[s1[1]-'a']++
		aa[s2[0]-'a']++
		aa[s2[1]-'a']++

		g := max(aa[s1[0]-'a'], aa[s1[1]-'a'], aa[s2[0]-'a'], aa[s2[1]-'a'])
		if g == 4 {
			fmt.Fprintln(out, 0)
		} else if g == 3 {
			fmt.Fprintln(out, 1)
		} else if g == 1 {
			fmt.Fprintln(out, 3)
		} else {
			if (s1[0] == s1[1] && s2[0] != s2[1]) || (s2[0] == s2[1] && s1[0] != s1[1]) {
				fmt.Fprintln(out, 2)
			} else {
				fmt.Fprintln(out, 1)
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		if s1[0] == s1[1] && s1[0] == s2[0] && s2[0] == s2[1] {
			fmt.Fprintln(out, 0)
		} else if s1[0] == s1[1] && s2[0] == s2[1] {
			fmt.Fprintln(out, 1)
		} else if (s1[0] == s2[0] || s1[0] == s2[1]) && (s1[1] == s2[0] || s1[1] == s2[1]) {
			fmt.Fprintln(out, 1)
		} else if (s1[0] == s1[1] && s2[0] != s2[1]) || (s1[0] != s1[1] && s2[0] == s2[1]) {
			fmt.Fprintln(out, 2)
		} else {
			fmt.Fprintln(out, 3)
		}
	}
}