Dima's spent much time thinking what present to give to Inna and gave her an empty sequence w. Now they want to fill sequence w with numbers zero and one. For that, they decided to play an amusing game. Before the game begins, Dima chooses m integers a1, a2, ..., am (1 ≤ a1 < a2 < ... < am). Then Inna and Dima start playing, that is, adding numbers to sequence w. Each new number they choose is added to the end of the sequence. At some moments of time Dima feels that the game is going to end too soon (and he wants to play with Inna as long as possible), so he hits a table hard with his fist. At that the a1-th, a2-th, a3-th, ..., ak-th numbers from the beginning simultaneously fall out of the sequence (the sequence gets k numbers less). Here k is such maximum number that value ak doesn't exceed the current length of the sequence. If number a1 is larger than the current length of w, then nothing falls out of the sequence.You are given the chronological sequence of events in the game. Each event is either adding a number to the end of sequence w or Dima's hit on the table. Calculate the sequence w after all these events happen.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106) showing how many events took place and how many numbers Dima chose. The next line contains m distinct integers ai (1 ≤ ai ≤ 106) sorted in the increasing order.  Next n lines describe the events in the chronological order. Each line contains a single integer: -1, 0 or 1. Number -1 means that Dima hits the table. Number 0 means that Inna and Dima add number 0 to the end of the sequence. Number 1 means that Inna and Dima add number 1 to the end of the sequence.

In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence. If after all events the sequence ends up empty, print "Poor stack!".

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

var t []int

func sum(r int) int {
	result := 0
	for ; r >= 0; r = (r & (r + 1)) - 1 {
		result += t[r]
	}
	return result
}

func inc(i, delta int) {
	for ; i < len(t); i = (i | (i + 1)) {
		t[i] += delta
	}
}

func set(i, value int) {
	inc(i, value-sum2(i, i))
}

func sum2(l, r int) int {
	return sum(r) - sum(l-1)
}

func nth(n int) int {
	return sort.Search(len(t), func(j int) bool {
		return sum(j) >= n
	})
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, op := make([]int, m), make([]int, n)
	for i := 0; i < m; i++ {
		a[i] = ni32()
	}
	b := []int{}
	for i := 0; i < n; i++ {
		op[i] = ni32()
		if op[i] != -1 {
			b = append(b, op[i])
		}
	}

	t = make([]int, len(b))
	cur, length := 0, 0

	for i := 0; i < n; i++ {
		if op[i] != -1 {
			set(cur, 1)
			cur++
			length++
		} else {
			length2 := length
			tmp := []int{}
			for j := 0; j < m && a[j] <= length; j++ {
				pos := nth(a[j])
				if pos < len(t) {
					tmp = append(tmp, pos)
					length2--
				} else {
					break
				}
			}
			for j := 0; j < len(tmp); j++ {
				set(tmp[j], 0)
			}
			length = length2
		}
	}

	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		for i := 0; i < len(b); i++ {
			if sum2(i, i) == 1 {
				pri32(b[i])
			}
		}
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

var t []int

func sum(r int) int {
	result := 0
	for ; r >= 0; r = (r & (r + 1)) - 1 {
		result += t[r]
	}
	return result
}

func inc(i, delta int) {
	for ; i < len(t); i = (i | (i + 1)) {
		t[i] += delta
	}
}

func set(i, value int) {
	inc(i, value-sum2(i, i))
}

func sum2(l, r int) int {
	return sum(r) - sum(l-1)
}

func nth(n int) int {
	return sort.Search(len(t), func(j int) bool {
		return sum(j) >= n
	})
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, op := make([]int, m), make([]int, n)
	for i := 0; i < m; i++ {
		a[i] = ni32()
	}
	b := []int{}
	for i := 0; i < n; i++ {
		op[i] = ni32()
		if op[i] != -1 {
			b = append(b, op[i])
		}
	}

	t = make([]int, len(b))
	tmp, ct := make([]int, len(b)), 0
	cur, length := 0, 0

	for i := 0; i < n; i++ {
		if op[i] != -1 {
			set(cur, 1)
			cur++
			length++
		} else {
			length2 := length
			ct = 0
			for j := 0; j < m && a[j] <= length; j++ {
				pos := nth(a[j])
				if pos < len(t) {
					tmp[ct] = pos
					ct++
					length2--
				} else {
					break
				}
			}
			for j := 0; j < ct; j++ {
				set(tmp[j], 0)
			}
			length = length2
		}
	}

	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		for i := 0; i < len(b); i++ {
			if sum2(i, i) == 1 {
				pri32(b[i])
			}
		}
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func sum(t []int, r int) int {
	result := 0
	for ; r >= 0; r = (r & (r + 1)) - 1 {
		result += t[r]
	}
	return result
}

func inc(t []int, i, delta int) {
	for ; i < len(t); i = (i | (i + 1)) {
		t[i] += delta
	}
}

func set(t []int, i, value int) {
	inc(t, i, value-sum2(t, i, i))
}

func sum2(t []int, l, r int) int {
	return sum(t, r) - sum(t, l-1)
}

func nth(t []int, n int) int {
	return sort.Search(len(t), func(j int) bool {
		return sum(t, j) >= n
	})
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, op := make([]int, m), make([]int, n)
	for i := 0; i < m; i++ {
		a[i] = ni32()
	}
	b := []int{}
	for i := 0; i < n; i++ {
		op[i] = ni32()
		if op[i] != -1 {
			b = append(b, op[i])
		}
	}

	t := make([]int, len(b))
	cur, length := 0, 0

	for i := 0; i < n; i++ {
		if op[i] != -1 {
			set(t, cur, 1)
			cur++
			length++
		} else {
			length2 := length
			tmp := []int{}
			for j := 0; j < m && a[j] <= length; j++ {
				pos := nth(t, a[j])
				if pos < len(t) {
					tmp = append(tmp, pos)
					length2--
				} else {
					break
				}
			}
			for j := 0; j < len(tmp); j++ {
				set(t, tmp[j], 0)
			}
			length = length2
		}
	}

	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		for i := 0; i < len(b); i++ {
			if sum2(t, i, i) == 1 {
				pri32(b[i])
			}
		}
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, t := make([]int, m), make([]int, n)
	st := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = ni32()
		if i == 0 {
			st[i] = a[i]
		} else {
			st[i] = max(st[i-1], a[i])
		}
	}
	b := []int{}
	for i := 0; i < n; i++ {
		t[i] = ni32()
		if t[i] != -1 {
			b = append(b, t[i])
		}
	}
	start, length := 0, 0
	for i := 0; i < n; i++ {
		if t[i] != -1 {
			length++
		} else {
			dl := sort.SearchInts(a, length+1)
			start += dl
			length -= dl
		}
	}
	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		pri32(b[start : start+length]...)
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, t := make([]int, m), make([]int, n)
	st := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = ni32()
		if i == 0 {
			st[i] = a[i]
		} else {
			st[i] = max(st[i-1], a[i])
		}
	}
	b := []int{}
	for i := 0; i < n; i++ {
		t[i] = ni32()
		if t[i] != -1 {
			b = append(b, t[i])
		}
	}
	start, length := 0, 0
	for i := 0; i < n; i++ {
		if t[i] != -1 {
			length++
		} else {
			dl := sort.SearchInts(st, length+1)
			start += dl
			length -= dl
		}
	}
	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		pri32(b[start : start+length]...)
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, t := make([]int, m), make([]int, n)
	st := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = ni32()
		if i == 0 {
			st[i] = a[i]
		} else {
			st[i] = max(st[i-1], a[i])
		}
	}
	b := []int{}
	for i := 0; i < n; i++ {
		t[i] = ni32()
		if t[i] != -1 {
			b = append(b, t[i])
		}
	}
	start, length := 0, 0
	for i := 0; i < n; i++ {
		if t[i] != -1 {
			length++
		} else {
			dl := min(sort.SearchInts(st, length+1), length)
			start += dl
			length -= dl
		}
	}
	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		pri32(b[start : start+length]...)
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, t := make([]int, m), make([]int, n)
	st := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = ni32()
		if i == 0 {
			st[i] = a[i]
		} else {
			st[i] = max(st[i-1], a[i])
		}
	}
	b := []int{}
	for i := 0; i < n; i++ {
		t[i] = ni32()
		if t[i] != -1 {
			b = append(b, t[i])
		}
	}
	start, length := 0, 0
	for i := 0; i < n; i++ {
		if t[i] != -1 {
			length++
		} else {
			dl := max(sort.SearchInts(st, length+1), length)
			start += dl
			length -= dl
		}
	}
	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		pri32(b[start : start+length]...)
		endl()
	}
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

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

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func ni64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		// sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

var t []int

func sum(r int) int {
	result := 0
	for ; r >= 0; r = (r & (r + 1)) - 1 {
		result += t[r]
	}
	return result
}

func inc(i, delta int) {
	for ; i < len(t); i = (i | (i + 1)) {
		t[i] += delta
	}
}

func set(i, value int) {
	inc(i, value-sum2(i, i))
}

func sum2(l, r int) int {
	return sum(r) - sum(l-1)
}

func nth(n int) int {
	return sort.Search(len(t), func(j int) bool {
		return sum(j) >= n
	})
}

func main() {
	defer w.Flush()
	n, m := ni32(), ni32()
	a, op := make([]int, m), make([]int, n)
	for i := 0; i < m; i++ {
		a[i] = ni32()
	}
	b := []int{}
	for i := 0; i < n; i++ {
		op[i] = ni32()
		if op[i] != -1 {
			b = append(b, op[i])
		}
	}

	t = make([]int, len(b))
	cur, length := 0, 0

	for i := 0; i < n; i++ {
		if op[i] != -1 {
			set(cur, 1)
			cur++
			length++
		} else {
			length2 := length
			for j := 0; j < m && a[j] <= length; j++ {
				fmt.Println(j, a[j])
				pos := nth(a[j])
				if pos < len(t) {
					set(pos, 0)
					length2--
				} else {
					break
				}
			}
			length = length2
		}
	}

	if length == 0 {
		w.WriteString("Poor stack!\n")
	} else {
		for i := 0; i < len(b); i++ {
			if sum2(i, i) == 1 {
				pri32(b[i])
			}
		}
		endl()
	}
}


You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:  The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened;  The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened.

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	in := scanInt()

	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n)

		f := true
		dec := false
		for i := 0; i < n; i++ {
			if !dec {
				if a[i] < i {
					dec = true
					if i!=0 && a[i-1] == n-1-i {
						f = false
					}
				}
			}

			if dec {
				if a[i] < n-1-i {
					f = false
				}
			}
		}

		if f {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		vals := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &vals[j])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%s\n", canSharpen(vals))
	}

	writer.Flush()
}

func canSharpen(vals []int) string {
	n := len(vals)

	if n == 1 {
		return "Yes"
	}

	pre := make([]bool, n)
	pre[0] = true
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] && vals[i] >= i
	}

	suf := make([]bool, n)
	suf[n-1] = true
	for i := n - 2; i >= 0; i-- {
		suf[i] = suf[i+1] && vals[i] >= (n-i-1)
	}

	for i := 0; i < n; i++ {
		if pre[i] && suf[i] {
			return "Yes"
		}
	}

	return "No"
}

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

package main

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

func run(_r io.Reader, _w io.Writer) {

	maxs := func(vals []int) int {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val > ans {
				ans = val
			}
		}
		return ans
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans bool) {
		var n int
		Fscan(in, &n)

		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if n == 1 {
			return true
		}
		mx := maxs(a)
		if mx == 0 {
			return
		}

		// 除了两边中间不能有 0

		isDesc := false
		top := 0
		//topI := 0
		for i, v := range a {
			if !isDesc && v>=i {
				top = v
				//topI = i

			} else {
				isDesc = true
				if top - 1<v {
					v = top-1
					if v < 0 {
						return
					}
				}
				top = v
			}

		}

		//var L,R int
		//for i, v := range a {
		//	if v == mx {
		//		L = i
		//		break
		//	}
		//}
		//for i := len(a) - 1; i >= 0; i-- {
		//	if a[i] == mx {
		//		R = i
		//		break
		//	}
		//}
		//for i :=0;i<L ;i++ {
		//
		//}

		return true
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		//if _case == 4{
		//	println()
		//}
		_ans := solve()
		Fprintln(out, map[bool]string{true: "Yes", false: "No"} [_ans])
	}
}

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

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	in := scanInt()

	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n)

		f1 := true
		dec := false
		c := 0
		for i := 0; i < n; i++ {
			if !dec {
				if a[i] < c {
					dec = true
					c -= 2
					if a[i] < c || c < 0 {
						f1 = false
					}
					c--
				} else {
					c++
				}
			} else {
				if a[i] < c || c < 0 {
					f1 = false
				}
				c--
			}
		}

		f2 := true
		dec = false
		c = 0
		for i := n-1; i >= 0; i-- {
			if !dec {
				if a[i] < c {
					dec = true
					c -= 2
					if a[i] < c || c < 0 {
						f2 = false
					}
					c--
				} else {
					c++
				}
			} else {
				if a[i] < c || c < 0 {
					f2 = false
				}
				c--
			}
		}

		if f1 || f2 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func run(_r io.Reader, _w io.Writer) {

	maxs := func(vals []int) int {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val > ans {
				ans = val
			}
		}
		return ans
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans bool) {
		var n int
		Fscan(in, &n)

		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if n == 1 {
			return true
		}
		mx := maxs(a)
		if mx == 0 {
			return
		}

		// 除了两边中间不能有 0

		isDesc := false
		top := 0
		topI := 0
		for i, v := range a {
			if !isDesc && v>=i {
				top = v
				topI = i
			} else {
				isDesc = true
				if top - (i-topI)<v {
					return
				}
				top = v
				topI = i
			}

		}

		//var L,R int
		//for i, v := range a {
		//	if v == mx {
		//		L = i
		//		break
		//	}
		//}
		//for i := len(a) - 1; i >= 0; i-- {
		//	if a[i] == mx {
		//		R = i
		//		break
		//	}
		//}
		//for i :=0;i<L ;i++ {
		//
		//}

		return true
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		_ans := solve()
		Fprintln(out, map[bool]string{true: "Yes", false: "No"} [_ans])
	}
}

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