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

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


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


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

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


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

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


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

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