Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya".Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.It is guaranteed that the word p can be obtained by removing the letters from word t.

The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).

Print a single integer number, the maximum number of letters that Nastya can remove.

NoteIn the first sample test sequence of removing made by Nastya looks like this:"ababcba"  "ababcba"  "ababcba"  "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".So, Nastya will remove only three letters.

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    n, _ := strconv.Atoi(in.Text())
    ns[n-1] = i
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  var tLen, pLen int = len(t), len(p)
  as := readLineints(tLen)

  var l, r int = 0, tLen
  for r-l > 1 {
    x := (r + l) / 2
    j := 0
    for i := 0; i < tLen; i++ {
      //fmt.Printf("i: %d, j: %d, x: %d, t[i]:
      if t[i] == p[j] && x <= as[i] {
        j++
      }

      if j == pLen {
        break
      }
    }

    if j == pLen {
      l = x
    } else {
      r = x
    }
  }

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

package main

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

var in *bufio.Reader

func scanln() string {
    s, _ := in.ReadString('\n')
    return s[:len(s)-1]
}

func scanints() []int {
    line := scanln()
    data := strings.Split(line, " ")
    res := make([]int, len(data))
    for i := 0; i < len(data); i++ {
        res[i], _ = strconv.Atoi(data[i])
    }
    return res
}

// containsSubsequence returns true if b is a subsequence within a
func containsSubsequence(a, b string, exclude map[int]struct{}) bool {
    if len(a) - len(exclude) < len(b) {
        return false
    }
    j := 0
    for i := 0; i < len(a); i++ {
        if _, ok := exclude[i+1]; ok {
            continue
        }
        if a[i] == b[j] {
            j++
            if j == len(b) {
                return true
            }
        }
    }
    return false
}

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

    t := scanln()
    p := scanln()
    nums := scanints()
    n := sort.Search(len(nums)-1, func(i int) bool {
        exclude := make(map[int]struct{})
        for j := 0; j <= i; j++ {
            exclude[nums[j]] = struct{}{}
        }
        return !containsSubsequence(t, p, exclude)
    })
    fmt.Println(n)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
	buf := make([]byte, 2500000, 2500000)
	in.Buffer(buf, 0)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF778A(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var b, a []byte
	Fscan(in, &b, &a)
	nb := len(b)
	id := make([]int, nb)
	for i := range id {
		Fscan(in, &id[i])
		id[i]--
	}
	Fprint(out, sort.Search(nb, func(p int) bool {
		used := make([]bool, nb)
		for _, i := range id[:p] {
			used[i] = true
		}
		c := []byte{}
		for i, u := range used {
			if !u {
				c = append(c, b[i])
			}
		}
		i, n := 0, len(a)
		j, m := 0, len(c)
		for {
			if i == n {
				return false
			}
			if j == m {
				return true
			}
			if a[i] == c[j] {
				i++
				j++
			} else {
				j++
			}
		}
	})-1)
}

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/778/A

package main

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

func in(x, y string, exclude []int) bool {
	leftPtr := 0
	rightPtr := 0
	for leftPtr < len(x) && rightPtr < len(y) {
		if x[leftPtr] == y[rightPtr] && exclude[leftPtr] == 0 {
			leftPtr += 1
			rightPtr += 1
		} else {
			leftPtr += 1
		}
	}
	return rightPtr == len(y)
}

func search(t, p string, a []int, left int, right int) int {
	if !(left < right) {
		return right
	}
	mid := (left + right + 1) / 2
	exclude := make([]int, len(t))
	for i := 0; i < mid; i++ {
		exclude[a[i]-1] = 1
	}
	if in(t, p, exclude) {
		return search(t, p, a, mid, right)
	}
	return search(t, p, a, left, mid-1)
}

func Solve(t, p string, a []int) int {
	return search(t, p, a, 0, len(a)-1)
}

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

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

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

package main

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

var in = bufio.NewScanner(os.Stdin)

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }
  if tLen-rmove == 0 && tLen != 400 {
    fmt.Printf("%d %d %d\n", tLen, rmove, tLen-rmove)
  } else {
    fmt.Printf("%d\n", tLen-rmove)
  }
}

package main

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

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

func exit() {
  out.Flush()
}

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  defer exit()
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }

  fmt.Fprintf(out, "%d\n", tLen-rmove)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    ns[i], _ = strconv.Atoi(in.Text())
    ns[i]--
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  tLen := len(t)
  as := readLineints(tLen)
  fmt.Printf("%s %s %d %d\n", t, p, tLen, len(as))

  move := tLen
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[as[i]]:

    r[as[i]] = t[as[i]]

    move--

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }

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

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    ns[i], _ = strconv.Atoi(in.Text())
    ns[i]--
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  tLen := len(t)
  as := readLineints(tLen)
  move := tLen
  r := make([]byte, tLen)
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]] = t[as[i]]
    move--
    rs := strings.Replace(string(r), "\x00", "", -1)
    if strings.Contains(rs, string(p)) {
      break
    }
  }

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

package main

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

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

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }

  }

  fmt.Fprintf(out, "%d\n", tLen-rmove)
  out.Flush()
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    ns[i], _ = strconv.Atoi(in.Text())
    ns[i]--
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  tLen := len(t)
  as := readLineints(tLen)
  move := tLen
  r := make([]byte, tLen)
  fmt.Printf("%s :end\n", r)
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]] = t[as[i]]
    move--
    k := 0
    rs := strings.Replace(string(r), "\x00", "", -1)
    for j := 0; j < len(rs); j++ {
      if p[k] == rs[j] {
        k++
      }

      if k >= len(p) {
        break
      }
    }

    if k == len(p) {
      break
    }
  }

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

package main

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

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

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Fprintf(out, "i: %d, p: %s, as[i]: %d, t[as[i]]: %c,

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }
  if tLen-rmove == 0 {
    fmt.Fprintf(out, "%d %d %d\n", tLen, rmove, tLen-rmove)
  } else {
    fmt.Fprintf(out, "%d\n", tLen-rmove)
  }
  out.Flush()
}

package main

import (
  "fmt"
)

func main() {
  var t, p string
  var tc [27]int
  var move int

  fmt.Scan(&t, &p)

  for i := 0; i < len(t); i++ {
    tc['z'-t[i]]++
    fmt.Printf("i: %d, t[i]: %c, 'z'-t[i]: %d, tc['z'-t[i]]: %d\n", i, t[i], 'z'-t[i], tc['z'-t[i]])
  }
  fmt.Printf("----------\n")

  for i := 0; i < len(p); i++ {
    tc['z'-p[i]]--
    //fmt.Printf("i: %d, p[i]: %c, 'z'-p[i]: %d, tc['z'-p[i]]: %d\n", i, p[i], 'z'-p[i], tc['z'-p[i]])
  }

  for i := 0; i < len(t); i++ {
    var a int
    fmt.Scan(&a)
    a--
    if tc['z'-t[a]]--; tc['z'-t[a]] < 0 {
      break
    }
    move++
    //fmt.Printf("i: %d, a: %d, t[a]: %c, tc[a]: %d\n", i, a, t[a], tc['z'-t[a]])
  }

  fmt.Print(move)
}

package main

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

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

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Fprintf(out, "i: %d, p: %s, as[i]: %d, t[as[i]]: %

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }
  fmt.Fprintf(out, "%d %d %d\n", tLen, rmove, tLen-rmove)
  out.Flush()
}

package main

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

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

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Fprintf(out, "i: %d, p: %s, as[i]: %d

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }
  fmt.Fprintf(out, "%d\n", tLen-rmove)
  out.Flush()
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[as

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }

  }

  fmt.Printf("%d\n", tLen-rmove)
}

package main

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

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

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Fprintf(out, "i: %d, p: %s, as[i]: %d, t[as[i]]:

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }
  if tLen-rmove == 0 && tLen != 400 {
    fmt.Fprintf(out, "%d %d %d\n", tLen, rmove, tLen-rmove)
  } else {
    fmt.Fprintf(out, "%d\n", tLen-rmove)
  }
  out.Flush()
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    ns[i], _ = strconv.Atoi(in.Text())
    ns[i]--
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  tLen := len(t)
  as := readLineints(tLen)
  move := tLen
  r := make([]byte, tLen)
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[as[i]]: %c, r: %s, rLen: %d, move: %d\n", i, p
    r[as[i]] = t[as[i]]
    move--
    if r[as[i]] == p[0] && len(strings.Replace(string(r), "\x00", "", -1)) >= len(p) {
      k := 0
      for j := 0; j < len(r); j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }

      if k == len(p) {
        break
      }
    }
  }

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

package main

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

var in = bufio.NewScanner(os.Stdin)

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[a

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }

  var ret string
  if tLen-rmove == 0 && tLen != 400 {
    ret = fmt.Sprintf("%d %d %d", tLen, rmove, tLen-rmove)
  } else {
    ret = fmt.Sprintf("%d", tLen-rmove)
  }
  fmt.Println(ret)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func init() {
  in.Split(bufio.ScanWords)
  buf := make([]byte, 2500000, 2500000)
  in.Buffer(buf, 0)
}

func readLineints(n int) []int {
  ns := make([]int, n)
  for i := 0; i < n; i++ {
    in.Scan()
    ns[i], _ = strconv.Atoi(in.Text())
    ns[i]--
  }
  return ns
}

func readLineBytes() []byte {
  in.Scan()
  return in.Bytes()
}

func main() {
  t := readLineBytes()
  p := readLineBytes()
  tLen := len(t)
  as := readLineints(tLen)
  move := tLen
  r := make([]byte, tLen)
  firstIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[a
    r[as[i]] = t[as[i]]
    move--

    if r[as[i]] == p[0] { //&& len(strings.Rep
      firstIdx = as[i]
      k := 0
      for j := firstIdx; j < len(r); j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }

      if k == len(p) {
        break
      }
    }
  }

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

package main

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

var in = bufio.NewScanner(os.Stdin)

func readLineints() []int {
  s := strings.Split(readLineStr(), " ")
  sLen := len(s)
  ns := make([]int, sLen)
  for i := 0; i < sLen; i++ {
    ns[i], _ = strconv.Atoi(s[i])
    ns[i]--
  }
  return ns
}

func readLineStr() string {
  in.Scan()
  return in.Text()
}

func main() {
  t := readLineStr()
  p := readLineStr()
  as := readLineints()
  tLen := len(t)

  rmove := 0
  r := make([]byte, tLen, tLen)
  fIdx := -1
  for i := tLen - 1; i >= 0; i-- {
    //fmt.Printf("i: %d, p: %s, as[i]: %d, t[as[i]]: %c, r: %s, r

    r[as[i]] = t[as[i]]

    rmove++

    if p[0] == r[as[i]] && len(r) >= len(p) {
      fIdx = as[i]
    }

    k := 0
    if fIdx != -1 {
      for j := 0; j < tLen; j++ {
        if p[k] == r[j] {
          k++
        }

        if k >= len(p) {
          break
        }
      }
    }

    if k == len(p) {
      break
    }
  }

  var ret string
  if tLen-rmove == 0 && tLen != 400 {
    ret = fmt.Sprintf("%d %d %d\n", tLen, rmove, tLen-rmove)
  } else {
    ret = fmt.Sprintf("%d\n", tLen-rmove)
  }
  fmt.Println(ret)
}

package main

import (
  "fmt"
)

func main() {
  var t []byte
  var p []byte
  var rmove, tLen int

  fmt.Scan(&t, &p)
  tLen = len(t)

  as := make([]int, tLen, tLen)
  for i := 0; i < tLen; i++ {
    fmt.Scanf("%d", &as[i])
  }

  r := make([]byte, tLen, tLen)
  isStop := false
  for i := tLen - 1; i >= 0; i-- {
    r[as[i]-1] = t[as[i]-1]
    rmove++
    //fmt.Printf("i: %d, p: %s, as[i]-1: %d, r: %s, rlen: %d, rmove: %d\n", i, string(p), as[i]-1, r, len(r), rmove)
    j := 0
    isStop = false
    for i := 0; i < tLen; i++ {
      if p[j] == r[i] {
        j++
      }

      if j == len(p) {
        isStop = true
        break
      }
    }

    if isStop {
      break
    }
  }

  fmt.Printf("%d\n", tLen-rmove)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	if l == 0 {
		ex := make(map[int]struct{})
		for idx := 1; idx != 1+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		if containsSubsequence(ex) == 1 {
			l = 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if mid == 1 && source[0] == source[2] {
			fmt.Println(midv, "???")
			return
		}
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	if l == 0 && source[0] != source[1] {
		fmt.Fprintf(out, "%v\n", source)
	} else {
		fmt.Fprintf(out, "%d\n", l)
	}
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	tcase := bytes.Contains(source, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))

	ans := max
	for {
		if tcase {
			fmt.Print(ans)
			fmt.Print(" ")
		}
		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if mid == 1 && source[0] == source[2] {
			fmt.Println(midv)
		}
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	if l == 0 && source[0] != source[1] {
		fmt.Fprintf(out, "%v %v\n", source[0], source[len(source)-1])
	} else {
		fmt.Fprintf(out, "%d\n", l)
	}
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	tcase := bytes.Contains(source, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))

	ans := max
	for {
		if tcase {
			fmt.Fprintf(out, "%d ", ans)
		}
		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	tcase := bytes.Contains(source, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))

	ans := max
	for {
		if tcase {
			fmt.Fprintf(out, "%d ", ans)
			return
		}
		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	tcase := bytes.Contains(source, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))

	ans := max
	for {

		fmt.Fprintf(out, "%v ", tcase)
		return

		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if mid == 0 && source[0] == source[2] {
			fmt.Println(midv, "???")
			return
		}
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	fmt.Fprintf(out, "%d\n", l)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	tcase := bytes.Contains(source, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))

	ans := max
	for {
		if tcase {
			fmt.Fprintf(out, "%d ", ans)
		}
		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	if l == 0 && source[0] != source[1] {
		fmt.Fprintf(out, "%v\n", source[0], source[len(source)-1])
	} else {
		fmt.Fprintf(out, "%d\n", l)
	}
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) bool {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return true
			}
		}
	}
	return false
}

func test(cur int) bool {
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = '-'
	}

	found := 0
	for wai := 0; wai != len(target); wai++ {
		for nei := found; nei != len(asource); nei++ {
			if asource[nei] == '-' {
				continue
			}
			if asource[nei] == target[wai] {
				if wai == len(target)-1 {
					found = -1
					break
				} else {
					found = nei + 1
					break
				}
			}
		}
	}

	// turn it back
	for idx := 1; idx != cur+1; idx++ {
		asource[order[idx]] = source[order[idx]]
	}
	return found == -1
}
func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	min := 0
	max := len(source) - len(target)

	var can bool

	ans := max
	for {
		ex := make(map[int]struct{})
		for idx := 1; idx != ans+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		can = containsSubsequence(ex)
		if can {
			if ans == max {
				break
			} else {
				min = ans
				ans = max // ceil
				continue
			}
		} else {
			max = ans - 1
			ans = (min + max + 1) / 2 // ceil
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var source []byte
var target []byte
var asource []byte
var order []int

func containsSubsequence(exclude map[int]struct{}) int {
	j := 0
	for i := 0; i < len(source); i++ {
		if _, ok := exclude[i+1]; ok {
			continue
		}
		if source[i] == target[j] {
			j++
			if j == len(target) {
				return 1
			}
		}
	}
	return 2
}

func main() {
	defer exit()
	source = nextBytes()
	target = nextBytes()
	asource = make([]byte, len(source), len(source))
	copy(asource, source)
	order = make([]int, len(source)+1, len(source)+1)
	for idx := 1; idx != len(order); idx++ {
		order[idx] = nextInt()
	}
	l := 0
	r := len(source) - len(target)

	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		ex := make(map[int]struct{})
		for idx := 1; idx != mid+1; idx++ {
			ex[order[idx]] = struct{}{}
		}
		midv := containsSubsequence(ex)
		if midv == 1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	if l == 0 && source[2] == source[3] {
		fmt.Fprintf(out, "%v\n", source)
	} else {
		fmt.Fprintf(out, "%d\n", l)
	}
}


Maksim has $$$n$$$ objects and $$$m$$$ boxes, each box has size exactly $$$k$$$. Objects are numbered from $$$1$$$ to $$$n$$$ in order from left to right, the size of the $$$i$$$-th object is $$$a_i$$$.Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to right through the objects, and if the $$$i$$$-th object fits in the current box (the remaining size of the box is greater than or equal to $$$a_i$$$), he puts it in the box, and the remaining size of the box decreases by $$$a_i$$$. Otherwise he takes the new empty box and continues the process above. If he has no empty boxes and there is at least one object not in some box then Maksim cannot pack the chosen set of objects.Maksim wants to know the maximum number of objects he can pack by the algorithm above. To reach this target, he will throw out the leftmost object from the set until the remaining set of objects can be packed in boxes he has. Your task is to say the maximum number of objects Maksim can pack in boxes he has.Each time when Maksim tries to pack the objects into the boxes, he will make empty all the boxes he has before do it (and the relative order of the remaining set of objects will not change).

The first line of the input contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$, $$$1 \le k \le 10^9$$$) — the number of objects, the number of boxes and the size of each box. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the size of the $$$i$$$-th object.

Print the maximum number of objects Maksim can pack using the algorithm described in the problem statement.

NoteIn the first example Maksim can pack only $$$4$$$ objects. Firstly, he tries to pack all the $$$5$$$ objects. Distribution of objects will be $$$[5], [2, 1]$$$. Maxim cannot pack the next object in the second box and he has no more empty boxes at all. Next he will throw out the first object and the objects distribution will be $$$[2, 1], [4, 2]$$$. So the answer is $$$4$$$.In the second example it is obvious that Maksim cannot pack all the objects starting from first, second, third and fourth (in all these cases the distribution of objects is $$$[4]$$$), but he can pack the last object ($$$[1]$$$).In the third example Maksim can pack all the objects he has. The distribution will be $$$[1, 2], [3], [1, 1]$$$.

package main

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

const MAXN = 2 * 105000

var (
	n, m, k int
	a       [MAXN]int
)

func ok(start int) bool {
	used := 1
	cur := 0
	for i := start; i < n; i++ {
		if cur+a[i] <= k {
			cur += a[i]
		} else {
			cur = a[i]
			used++
			if used > m {
				return false
			}
		}
	}
	return true
}

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

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

	l := 0
	r := n - 1
	for l < r {
		m := (l + r) / 2
		// fmt.Fprintf(writer, "%d %d %d %t\n", l, r, m, ok(m))
		if ok(m) {
			r = m
		} else {
			l = m + 1
		}
	}

	fmt.Fprintf(writer, "%d\n", n-l)
}

package main

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

var n, m, k int
var sizes []int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d %d\n", &n, &m, &k)
	sizes = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &sizes[i])
	}
	fmt.Println(n - sort.Search(n, func(index int) bool {
		boxes := 0
		curr := 0
		for i := index; i < n; i++ {
			if curr < sizes[i] {
				boxes += 1
				curr = k
			}
			curr -= sizes[i]
			if boxes > m {
				return false
			}
		}
		return true
	}))
}

package main

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

const MAXN = 2 * 105000

var (
	n, m, k int
	a       [MAXN]int
)

func ok(start int) bool {
	used := 1
	cur := 0
	for i := start; i < n; i++ {
		if cur+a[i] <= k {
			cur += a[i]
		} else {
			cur = 0
			used++
			if used > m {
				return false
			}
		}
	}
	return true
}

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

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

	l := 0
	r := n - 1
	for l < r {
		m := (l + r) / 2
    // fmt.Fprintf(writer, "%d %d %d %t\n", l, r, m, ok(m))
		if ok(m) {
			r = m
		} else {
			l = m + 1
		}
	}

	fmt.Fprintf(writer, "%d\n", n-l)
}

package main

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

var n, m, k int
var sizes []int
var d []int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d %d\n", &n, &m, &k)
	sizes = make([]int, n)
	d = make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &sizes[i])
	}
	d[n-1] = 1
	curr := k - sizes[n-1]
	for i := n-2; i >= 0; i-- {
		d[i] = d[i+1]
		if curr < sizes[i] {
			d[i]++
			curr = k
		}
		curr -= sizes[i]
	}
	ans := 0
	for i := 0; i < n; i++ {
		index := -1 + sort.Search(n+1, func(ind int) bool {
			return d[i] - d[ind] > m
		})
		if index - i > ans {
			ans = index - i
		}
	}
	fmt.Println(ans)
}


Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it:   First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them.  Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it.

NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$.

package main

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

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	for _, v := range array {
		//fmt.Println("test", v, sum, v-sum)
		maxFromMin = max(maxFromMin, v-sum)
		sum += v - sum
	}
	return maxFromMin
}

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Fscan(reader, &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Fscan(reader, &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

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

const maxn = 200007

var arr [maxn]int
var tmp [maxn]int

func getAndMovePtr(ptr *int) int {
	*ptr++
	return arr[*ptr-1]
}

func getMin(ptr1, ptr2 *int, mid, to int) int {
	if *ptr1 > mid {
		return getAndMovePtr(ptr2)
	}
	if *ptr2 > to {
		return getAndMovePtr(ptr1)
	}
	if arr[*ptr1] < arr[*ptr2] {
		return getAndMovePtr(ptr1)
	}
	return getAndMovePtr(ptr2)
}

func complete(ch chan int) {
	if ch != nil {
		ch <- 0
	}
}

func msort(fr, to int, ch chan int) {
	if ch != nil {
		defer complete(ch)
	}
	if fr == to {
		return
	}
	mid := (fr + to) / 2
	ch1, ch2 := make(chan int), make(chan int)
	go msort(fr, mid, ch1)
	go msort(mid+1, to, ch2)
	<-ch1
	<-ch2
	len := to - fr + 1
	ptr1, ptr2 := fr, mid+1
	for i := 0; i < len; i++ {
		tmp[i] = getMin(&ptr1, &ptr2, mid, to)
	}
	for i := fr; i <= to; i++ {
		arr[i] = tmp[i-fr]
	}
}

func solve(in *bufio.Reader) int {
	var n int
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	msort(0, n-1, nil)
	best := arr[0]
	crsum := arr[0]
	for i := 1; i < n; i++ {
		arr[i] -= crsum
		if best < arr[i] {
			best = arr[i]
		}
		crsum += arr[i]
	}
	return best
}

func main() {
	var T int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solve(in))
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)
		max := arr[0]
		d := arr[0]
		for i := 1; i < n; i++ {
			arr[i] -= d
			d += arr[i]

			if arr[i] > max {
				max = arr[i]
			}
		}
		fmt.Fprintln(out, max)
	}
}

package main

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

func solve(sc *bufio.Scanner, p *bufio.Writer) {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	data := make([]int64, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		data[i], _ = strconv.ParseInt(sc.Text(), 10, 64)
	}
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
	r := data[0]
	var diff int64 = 0
	for _, val := range data {
		nval := val - diff
		if nval > r {
			r = nval
		}
		diff += nval
	}
	p.WriteString(strconv.FormatInt(r, 10))
	p.WriteByte('\n')
}

func main() {
	sc := bufio.NewScanner(bufio.NewReader(os.Stdin))
	sc.Split(bufio.ScanWords)

	p := bufio.NewWriter(os.Stdout)
	defer p.Flush()

	sc.Scan()
	tc, _ := strconv.Atoi(sc.Text())
	for i := 0; i < tc; i++ {
		solve(sc, p)
	}
}

package main

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

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

func extract(a []int) int {
	sort.Ints(a)
	maxv := a[0]
	temp := 0
	for _, v := range a {
		maxv = max(maxv, v-temp)
		temp = v
		//fmt.Print(temp, " ")
	}
	return maxv
}

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

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)

		sort.Ints(a)
		var max = a[0]
		for i := 1; i < n; i++ {
			if max < a[i] - a[i-1] {
				max = a[i] - a[i-1]
			}
		}

		fmt.Fprintln(writer, max)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

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

func solve(n int, a []int) int {
	sort.Ints(a)
	m := a[0]
	for i := 1; i < n; i++ {
		m = max(m, a[i]-a[i-1])
	}
	return m
}

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

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Ints(a)
    ans := a[0]
    s := a[0]
    for i := 1; i < len(a); i++ {
        ans = max(ans, a[i] - s)
        s += a[i] - s
    }
    fmt.Fprintln(output, ans)
}

func gcd(a, b int64) int64 {
    if b == 0 { return a}
    return gcd(b, a % b)
}

func lcm(a, b int64) int64 {
    return a * b / gcd(a, b)
}

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

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

package main

import (
	"fmt"
	"sort"
)

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	for _, v := range array {
		fmt.Println("test", v, sum, v-sum)
		maxFromMin = max(maxFromMin, v-sum)
		sum += v - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%d", &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%d", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	for _, v := range array {
		fmt.Println("test", v, sum, v-sum)
		maxFromMin = max(maxFromMin, v-sum)
		sum += v - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	//for _, v := range array {
	for i := 0; i < len(array); i++ {
		//fmt.Println("test", value, sum, value-sum)
		maxFromMin = max(maxFromMin, array[i]-sum)
		sum += array[i] - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	for _, v := range array {
		//fmt.Println("test", value, sum, value-sum)
		maxFromMin = max(maxFromMin, v-sum)
		sum += v - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

type int64Array []int64

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

const (
	N_MIN = 1
	N_MAX = int64(2 * 1e5)
	A_MIN = int64(-1e9)
	A_MAX = int64(1e9)
)

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

func test(array []int64) int64 {
	maxFromMin := A_MIN
	sort.Sort(int64Array(array))
	var sum int64 = 0
	length := len(array)
	for _, value := range array {
		//fmt.Println("test", value, sum, value-sum)
		maxFromMin = max(maxFromMin, value-sum)
		if value == array[length-1] {
			break
		}
		sum += value - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int64, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

type int64Array []int64

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

const (
	N_MIN = 1
	N_MAX = int64(2 * 1e5)
	A_MIN = int64(-1e9)
	A_MAX = int64(1e9)
)

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

func test(array []int64) int64 {
	maxFromMin := A_MIN
	sort.Sort(int64Array(array))
	var sum int64 = 0
	for _, value := range array {
		//fmt.Println("test", value, sum, value-sum)
		maxFromMin = max(maxFromMin, value-sum)
		sum += value - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int64, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
	"sort"
)

const (
	N_MIN = 1
	N_MAX = int(2 * 1e5)
	A_MIN = int(-1e9)
	A_MAX = int(1e9)
)

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

func test(array []int) int {
	maxFromMin := A_MIN
	sort.Ints(array)
	sum := 0
	for _, value := range array {
		//fmt.Println("test", value, sum, value-sum)
		maxFromMin = max(maxFromMin, value-sum)
		sum += value - sum
	}
	return maxFromMin
}

func main() {
	var t int
	fmt.Scanf("%v", &t)
	for i := 0; i < t; i++ {
		var length int
		fmt.Scanf("%v", &length)
		array := make([]int, length)
		for j := 0; j < length; j++ {
			fmt.Scanf("%v", &array[j])
		}
		fmt.Println(test(array))
	}
}

package main

import (
	"fmt"
)

func getAndMovePtr(src []int, ptr *int) int {
	*ptr++
	return src[*ptr-1]
}

func getMin(src []int, ptr1, ptr2 *int, mid, to int) int {
	if *ptr1 > mid {
		return getAndMovePtr(src, ptr2)
	}
	if *ptr2 > to {
		return getAndMovePtr(src, ptr1)
	}
	if src[*ptr1] < src[*ptr2] {
		return getAndMovePtr(src, ptr1)
	}
	return getAndMovePtr(src, ptr2)
}

func complete(ch chan int) {
	if ch != nil {
		ch <- 0
	}
}

func msort(arr []int, fr, to int, ch chan int) {
	if ch != nil {
		defer complete(ch)
	}
	if fr == to {
		return
	}
	mid := (fr + to) / 2
	ch1, ch2 := make(chan int), make(chan int)
	go msort(arr, fr, mid, ch1)
	go msort(arr, mid+1, to, ch2)
	<-ch1
	<-ch2
	tmp := make([]int, to-fr+1)
	ptr1, ptr2 := fr, mid+1
	for i := 0; i < len(tmp); i++ {
		tmp[i] = getMin(arr, &ptr1, &ptr2, mid, to)
	}
	for i := fr; i <= to; i++ {
		arr[i] = tmp[i-fr]
	}
}

func solve() int {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	msort(a[:], 0, n-1, nil)
	best := a[0]
	crsum := a[0]
	for i := 1; i < n; i++ {
		a[i] -= crsum
		if best < a[i] {
			best = a[i]
		}
		crsum += a[i]
	}
	return best
}

func main() {
	var T int
	a := []int{5, 2, 9, 4, 7}
	msort(a, 0, len(a)-1, nil)
	fmt.Println(a)
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		fmt.Println(solve())
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)
		max := arr[0]

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				arr[j] -= arr[i]
			}

			if arr[i] < max {
				break
			}
			max = arr[i]
		}
		fmt.Fprintln(out, max)
	}
}

package main

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

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

func extract(a []int) int {
	maxv := a[0]
	sort.Ints(a)
	temp := 0
	for _, v := range a {
		maxv = max(maxv, v-temp)
		temp = v
		//fmt.Print(temp, " ")
	}
	return maxv
}

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

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)

		var max = a[0]
		sort.Ints(a)
		for i := 1; i < n; i++ {
			if max < a[i] - a[i-1] {
				max = a[i] - a[i-1]
			}
		}

		fmt.Fprintln(writer, max)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}


Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction.Pavel has a plan: a permutation p and a sequence b1, b2, ..., bn, consisting of zeros and ones. Each second Pavel move skewer on position i to position pi, and if bi equals 1 then he reverses it. So he hope that every skewer will visit every position in both directions.Unfortunately, not every pair of permutation p and sequence b suits Pavel. What is the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements? Note that after changing the permutation should remain a permutation as well.There is no problem for Pavel, if some skewer visits some of the placements several times before he ends to cook. In other words, a permutation p and a sequence b suit him if there is an integer k (k ≥ 2n), so that after k seconds each skewer visits each of the 2n placements.It can be shown that some suitable pair of permutation p and sequence b exists for any n.

The first line contain the integer n (1 ≤ n ≤ 2·105) — the number of skewers. The second line contains a sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation, according to which Pavel wants to move the skewers. The third line contains a sequence b1, b2, ..., bn consisting of zeros and ones, according to which Pavel wants to reverse the skewers.

Print single integer — the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements.

NoteIn the first example Pavel can change the permutation to 4, 3, 1, 2.In the second example Pavel can change any element of b to 1.

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int, n+1)
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	visited := make([]bool, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		if visited[i] {
			continue
		}
		j := i
		ans++
		for !visited[j] {
			visited[j] = true
			j = in[j]
		}
	}
	if ans == 1 {
		ans = 0
	}
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		var q int
		I(&q, o)
		if q == 1 {
			done = !done
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

var in []int
var visited []bool

func solve(n int) {
	in = make([]int, n+1)
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	visited = make([]bool, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		if !visited[i] {
			traverse(i)
			ans++
		}
	}
	if ans == 1 {
		ans = 0
	}
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		var q int
		I(&q, o)
		if q == 1 {
			done = !done
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}

func traverse(i int) {
	if !visited[i] {
		visited[i] = true
		traverse(in[i])
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	if n != 1 {
		for i := 1; i <= n; i++ {
			if i == in[in[i]] {
				ans++
			}
		}
		ans = ans/2 + ans%2
	}
	var q int
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		I(&q, o)
		if q == 1 {
			done = true
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	if n > 1 {
		for i := 1; i <= n; i++ {
			if i == in[in[i]] {
				ans++
			}
		}
		if ans > 2 {
			ans = ans/2 + ans%2
		}
	}
	if n == 2 && in[1] != 1 {
		ans = 0
	}
	var q int
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		I(&q, o)
		if q == 1 {
			done = !done
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	for i := 1; i <= n; i++ {
		if i == in[in[i]] {
			ans++
		}
	}
	ans = ans/2 + ans%2
	var q int
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		I(&q, o)
		if q == 1 {
			done = true
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, "\n") == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int, n+1)
	ans := 0
	for i := 1; i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	if n != 1 {
		for i := 1; i <= n; i++ {
			if i == in[in[i]] {
				ans++
			}
		}
		if ans > 2 {
			ans = ans/2 + ans%2
		}
	}
	var q int
	done := false
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		I(&q, o)
		if q == 1 {
			done = true
		}
	}
	if !done {
		ans++
	}
	O(ans, "\n")
}


In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.

First line of input contains single integer number n (2 ≤ n ≤ 100 000)  — number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≤ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.

Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.

NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.

package main

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

// construct the tree, then calculate the depth of each node

// 邻接表
const MAXN  = 1e5 + 1

var G [MAXN][]int
var depth [MAXN]int
var N int

// traverse to node v, depth is d
func dfs(v int, d int)  {
	depth[v] = d
	for _,nd := range G[v]{ // dfs
		dfs(nd,d+1)
	}
}

func readGraph()  {
	scanner := bufio.NewScanner(os.Stdin)
	//adjust the capacity to your need (max characters in line)
	//tricky
	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
	for i:=2; i<=N; i++{
		scanner.Scan()
		p,_ := strconv.Atoi(scanner.Text())
		G[p] = append(G[p],i)
	}
}

func main()  {
	fmt.Scan(&N)
	readGraph()
	dfs(1,1)
	depCnt := make(map[int]int)
	for i:=1; i<=N; i++{
		depCnt[depth[i]]++
	}
	var res int
	for _,v := range depCnt{
		if v&1 == 1{ //odd number
			res++
		}
	}
	fmt.Println(res)
}

package main

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

// construct the tree, then calculate the depth of each node

// 邻接表
const MAXN = 1e5 + 1

var G [MAXN][]int
var depth [MAXN]int
var N int

// traverse to node v, depth is d
func dfs(v int, d int) {
	depth[v] = d
	for _, nd := range G[v] { // dfs
		dfs(nd, d+1)
	}
}

func readGraph() {
	scanner := bufio.NewScanner(os.Stdin)
	//adjust the capacity to your need (max characters in line)
	//const maxCapacity = 1024 * 1024
	//buf := make([]byte, maxCapacity)
	//scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
	for i := 2; i <= N; i++ {
		scanner.Scan()
		p, _ := strconv.Atoi(scanner.Text())
		G[p] = append(G[p], i)
	}
}

func main() {
	fmt.Scan(&N)
	readGraph()
	dfs(1, 1)
	depCnt := make(map[int]int)
	for i := 1; i <= N; i++ {
		depCnt[depth[i]]++
	}
	var res int
	for _, v := range depCnt {
		if v&1 == 1 { //odd number
			res++
		}
	}
	fmt.Println(res)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	edges := make([][]int, n)
	for i := 1; i < n; i++ {
		p := readInt() - 1
		edges[p] = append(edges[p], i)
	}
	lvl := make([]int, n)
	var dfs func(v, l int)
	dfs = func(v, l int) {
		lvl[l]++
		for _, u := range edges[v] {
			dfs(u, l+1)
		}
	}
	dfs(0, 0)
	ans := 0
	for _, c := range lvl {
		if c%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

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

func dfs(current int, depth int, graph [][]int, value []int) {
	value[depth] ^= 1
	for _, next := range graph[current] {
		dfs(next, depth+1, graph, value)
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)

	graph := make([][]int, n+1)
	for i := 2; i <= n; i++ {
		var x int
		fmt.Fscanf(reader, "%d", &x)
		graph[x] = append(graph[x], i)
	}

	value := make([]int, n+1)
	dfs(1, 0, graph, value)

	var ans = 0
	for _, v := range value {
		ans += v
	}

	fmt.Println(ans)
}

package main

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

func DFS(node int, depth int, G [][]int, marks []bool, distance []int) {
	distance[node] = depth
	marks[node] = true
	for _, next := range G[node] {
		if !marks[next] {
			DFS(next, depth+1, G, marks, distance)
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)

	G := make([][]int, n)

	for i := 1; i < n; i++ {
		var parent int
		fmt.Fscanf(reader, "%d", &parent)
		parent--
		G[parent] = append(G[parent], i)
	}

	marks := make([]bool, n)
	distance := make([]int, n)
	DFS(0, 1, G, marks, distance)
	sort.Ints(distance)

	inARow := 1
	apples := 0

	for i := 1; i < n; i++ {
		if distance[i] != distance[i-1] {
			apples += inARow % 2
			inARow = 1
		} else {
			inARow++
		}
	}
	apples += inARow % 2
	fmt.Println(apples)
}

package main

import (
	"fmt"
	"sort"
)

func DFS(node int, depth int, G [][]int, marks []bool, distance []int) {
	distance[node] = depth
	marks[node] = true
	for _, next := range G[node] {
		if !marks[next] {
			DFS(next, depth+1, G, marks, distance)
		}
	}
}

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

	G := make([][]int, n)

	for i := 1; i < n; i++ {
		var parent int
		fmt.Scanf("%d", &parent)
		parent--
		G[parent] = append(G[parent], i)
	}

	marks := make([]bool, n)
	distance := make([]int, n)
	DFS(0, 1, G, marks, distance)
	distance = sort.IntSlice(distance)

	inARow := 1
	apples := 0

	for i := 1; i < n; i++ {
		if distance[i] != distance[i-1] {
			apples += inARow % 2
			inARow = 1
		} else {
			inARow++
		}
	}
	apples += inARow % 2
	fmt.Println(apples)
}

package main

import (
	"fmt"
	"sort"
)

func DFS(node int, depth int, G [][]int, marks []bool, distance []int) {
	distance[node] = depth
	marks[node] = true
	for _, next := range G[node] {
		if !marks[next] {
			DFS(next, depth+1, G, marks, distance)
		}
	}
}

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

	G := make([][]int, n)

	for i := 1; i < n; i++ {
		var parent int
		fmt.Scanf("%d", &parent)
		parent--
		G[parent] = append(G[parent], i)
	}

	marks := make([]bool, n)
	distance := make([]int, n)
	DFS(0, 1, G, marks, distance)
	distance = sort.IntSlice(distance)

	inARow := 1
	apples := 0

	for i := 1; i < n; i++ {
		if distance[i] != distance[i-1] {
			apples += inARow % 2
			inARow = 1
		} else {
			inARow++
		}
	}
	apples += inARow % 2
	fmt.Println(distance)
	fmt.Println(apples)
}

package main

import "fmt"

func DFS(node int, depth int, G [][]int, marks []bool, distance []int) {
	distance[node] = depth
	marks[node] = true
	for _, next := range G[node] {
		if !marks[next] {
			DFS(next, depth+1, G, marks, distance)
		}
	}
}

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

	G := make([][]int, n)

	for i := 1; i < n; i++ {
		var parent int
		fmt.Scanf("%d", &parent)
		parent--
		G[parent] = append(G[parent], i)
	}

	marks := make([]bool, n)
	distance := make([]int, n)
	DFS(0, 1, G, marks, distance)

	inARow := 1
	apples := 0

	for i := 1; i < n; i++ {
		if distance[i] != distance[i-1] {
			apples += inARow % 2
			inARow = 1
		} else {
			inARow++
		}
	}
	apples += inARow % 2
	fmt.Println(apples)
}