There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:   alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;  erase x — to erase the block with the identifier x;  defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

The first line of the input data contains two positive integers t and m (1 ≤ t ≤ 100;1 ≤ m ≤ 100), where t — the amount of operations given to the memory manager for processing, and m — the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1 ≤ n ≤ 100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.

Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.

6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type Block struct {
	id        int
	length    int
	nextBlock *Block
}

func printMemory(mem *Block) {
	for p := mem; p != nil; p = p.nextBlock {
		fmt.Printf("id=%d length=%d\n", p.id, p.length)
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var t, m int
	fmt.Fscanf(reader, "%d %d\n", &t, &m)
	nextId := 1
	memory := &Block{0, m, nil}

	for i := 0; i < t; i++ {
		var op string
		var x int
		fmt.Fscanf(reader, "%s", &op)
		switch op {
		case "alloc":
			fmt.Fscanf(reader, " %d\n", &x)
			flag := false
			for p := memory; p != nil; p = p.nextBlock {
				if p.id == 0 {
					for q := p.nextBlock; q != nil && q.id == 0; q = p.nextBlock {
						p.nextBlock = q.nextBlock
						p.length += q.length
					}
				} else {
					continue
				}
				if p.length == x {
					p.id = nextId
					nextId++
					fmt.Printf("%d\n", p.id)
					flag = true
					break
				} else if p.length > x {
					q := &Block{0, p.length - x, p.nextBlock}
					p.length = x
					p.nextBlock = q
					p.id = nextId
					nextId++
					fmt.Printf("%d\n", p.id)
					flag = true
					break
				}
			}
			if !flag {
				fmt.Printf("NULL\n")
			}
		case "erase":
			fmt.Fscanf(reader, " %d\n", &x)
			flag := false
			for p := memory; p != nil; p = p.nextBlock {
				if p.id == x && p.id != 0 {
					p.id = 0
					flag = true
				}
			}
			if !flag {
				fmt.Printf("ILLEGAL_ERASE_ARGUMENT\n")
			}
		case "defragment":
			fmt.Fscanf(reader, "\n")
			for p := memory; p != nil && p.nextBlock != nil; p = p.nextBlock {
				if p.id != 0 {
					continue
				}
				for q := p.nextBlock; q != nil; q = p.nextBlock {
					if p.id == 0 && q.id == 0 {
						p.length += q.length
						p.nextBlock = q.nextBlock
					} else if p.id == 0 && q.id != 0 {
						p.id, q.id = q.id, p.id
						p.length, q.length = q.length, p.length
						break
					} else {
						break
					}
				}
			}
		}
	}
}

package main

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

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

	t, m := readTwoNums(reader)

	manager := NewManager(m)

	var buf bytes.Buffer

	for t > 0 {
		t--
		s, _ := reader.ReadBytes('\n')

		if s[0] == 'a' {
			var n int
			readInt(s, len("alloc "), &n)
			id := manager.Alloc(n)

			if id < 0 {
				buf.WriteString("NULL\n")
			} else {
				buf.WriteString(fmt.Sprintf("%d\n", id))
			}
		} else if s[0] == 'e' {
			var x int
			readInt(s, len("erase "), &x)
			ok := manager.Erase(x)
			if !ok {
				buf.WriteString("ILLEGAL_ERASE_ARGUMENT\n")
			}
		} else {
			manager.Defragment()
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

type Node struct {
	next *Node
	sz   int
	pos  int
	id   int
}

func NewNode(pos int, sz int) *Node {
	node := new(Node)
	node.pos = pos
	node.sz = sz
	return node
}

type Manager struct {
	free *Node
	used *Node
	mem  map[int]*Node
	p    int
	tot  int
}

func NewManager(m int) Manager {
	free := new(Node)
	free.next = NewNode(0, m)
	used := new(Node)
	mem := make(map[int]*Node)
	return Manager{free, used, mem, 0, m}
}

func (this *Manager) Alloc(n int) int {
	head := this.free

	for head.next != nil && head.next.sz < n {
		head = head.next
	}

	if head.next == nil {
		return -1
	}

	tmp := head.next

	pos := tmp.pos

	var tmp2 *Node

	if tmp.sz > n {
		tmp.sz -= n
		tmp.pos += n
		tmp2 = NewNode(pos, n)
	} else {
		head.next = tmp.next
		tmp.next = nil
		tmp2 = tmp
	}

	head = this.used

	for head.next != nil && head.next.pos < pos {
		head = head.next
	}

	tmp2.next = head.next
	head.next = tmp2

	this.p++
	this.mem[this.p] = tmp2
	tmp2.id = this.p

	return this.p
}

func (this *Manager) Erase(x int) bool {
	if node, found := this.mem[x]; !found {
		return false
	} else {
		delete(this.mem, x)

		head := this.used
		//remove it from used
		for head.next != nil && head.next != node {
			head = head.next
		}

		if head.next == nil {
			return false
		}

		head.next = node.next
		node.next = nil
		// put back as free
		head = this.free

		for head.next != nil && head.next.pos < node.pos {
			head = head.next
		}
		// head.pos < pos && ( head.next == nil || head.next.pos > pos)

		node.id = -1
		node.next = head.next
		head.next = node

		if head == this.free {
			head = head.next
		}

		for head.next != nil && head.pos+head.sz == head.next.pos {
			head.sz += head.next.sz
			head.next = head.next.next
		}

		return true
	}
}

func (this *Manager) Defragment() {
	head := this.used
	var sz int

	for head.next != nil {
		cur := head.next
		cur.pos = sz
		sz += cur.sz
		head = head.next
	}

	if this.tot > sz {
		this.free.next = NewNode(sz, this.tot-sz)
	} else {
		this.free.next = nil
	}
}

package main

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

func solve() {
	t := readInt()
	m := readInt()

	mem := make([]int, m)
	xid := 1

	for i := 0; i < t; i++ {
		op := readString()
		if op == "alloc" {
			id := readInt()
			cnt := 0
			idx := 0
			for i, v := range mem {
				if v == 0 {
					if cnt == 0 {
						idx = i
					}
					cnt++
					if cnt == id {
						break
					}
				} else {
					cnt = 0
				}
			}
			if cnt == id {
				for i := 0; i < id; i++ {
					mem[idx+i] = xid
				}
				fmt.Println(xid)
				xid++
			} else {
				fmt.Println("NULL")
			}
		} else if op == "erase" {
			found := false
			id := readInt()
			if id <= 0 {
				fmt.Println("ILLEGAL_ERASE_ARGUMENT")
				continue
			}

			for i, v := range mem {
				if v == id {
					found = true
					mem[i] = 0
				}
			}
			if !found {
				fmt.Println("ILLEGAL_ERASE_ARGUMENT")
			}
		} else if op == "defragment" {
			nmem := make([]int, m)
			n := 0
			for _, v := range mem {
				if v == 0 {
					continue
				}
				nmem[n] = v
				n++
			}
			mem = nmem
		} else {
			panic(op)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Block struct {
  Pos, Size int
}
type Blocks []*Block
func (blocks Blocks) Len() int {
  return len(blocks)
}
func (blocks Blocks) Swap(i, j int) {
  blocks[i], blocks[j] = blocks[j], blocks[i]
}
func (blocks Blocks) Less(i, j int) bool {
  return blocks[i].Pos < blocks[j].Pos
}

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

  var q, n int
  line, _ := reader.ReadString('\n')
  fmt.Sscanf(line, "%d %d", &q, &n)
  free := map[int]int{ 0: n }
  reserved := map[int]*Block{}
  lastId := 0
  for qi := 0; qi < q; qi++ {
    line, _ = reader.ReadString('\n')
    tokens := strings.Split(strings.TrimSpace(line), " ")
    //--- Allocate a block
    if tokens[0] == "alloc" {
      size, _ := strconv.Atoi(tokens[1])
      allocated := false
      for pos := 0; pos < n; pos++ {
        if free[pos] >= size {
          lastId++
          block := Block{ pos, size }
          reserved[lastId] = &block
          //writer.WriteString(fmt.Sprintf("allocated: pos = %d, size = %d\n",
          //    block.Pos, block.Size))
          free[pos+size] = free[pos]-size
          free[pos] = 0
          allocated = true
          break
        }
      }
      if !allocated {
        writer.WriteString("NULL\n")
      } else {
        writer.WriteString(fmt.Sprintf("%d\n", lastId))
      }
    //--- Erase a block
    } else if tokens[0] == "erase" {
      id, _ := strconv.Atoi(tokens[1])
      block, found := reserved[id]
      if !found {
        writer.WriteString("ILLEGAL_ERASE_ARGUMENT\n")
      } else {
        delete(reserved, id)
        tail := block.Pos + block.Size
        block.Size += free[tail]
        free[tail] = 0
        head := block.Pos
        for pos := head-1; pos >= 0; pos-- {
          if pos+free[pos] == head {
            head = pos
            block.Size += free[head]
            break
          }
        }
        free[head] = block.Size
        //writer.WriteString(fmt.Sprintf("freed: pos = %d, size = %d\n",
        //    head, block.Size))
      }
    //--- Shift blocks to the left
    } else {
      blocks := []*Block{}
      for _, block := range reserved {
        blocks = append(blocks, block)
      }
      sort.Sort(Blocks(blocks))
      tail := 0
      for _, block := range blocks {
        free[block.Pos + block.Size] = 0
        block.Pos = tail
        tail += block.Size
      }
      free[tail] = n-tail
    }
  }
}

package main

import (
	"strings"
	"fmt"
	"strconv"
	"errors"
	"io"
	"unicode/utf8"
	"bytes"
	"os"
)

type block struct {
	i, sz int
}
func main() {
	t, m, s := nextInt(), nextInt(), 1
	mem := make([]*block, 1)
	mem[0] = &block{0, m}
	for i := 0; i < t; i++ {
		op := nextWord()
		switch op {
		case "defragment":
			newMem := make([]*block, 0)
			sz := 0
			for _, b := range mem {
				if b.i != 0 {
					sz += b.sz
					newMem = append(newMem, b)
				}
			}
			if m - sz > 0 {
				mem = append(newMem, &block{0, m - sz})
			}
		case "alloc":
			sz, _ := strconv.Atoi(nextWord())
			allocated := false
			for i, b := range mem {
				if b.i == 0 && b.sz >= sz {
					allocated = true
					b.sz -= sz
					newMem := make([]*block, i)
					copy(newMem, mem)
					newMem = append(newMem, &block{s, sz})
					if b.sz > 0 {
						mem = append(newMem, mem[i:]...)
					} else {
						mem = append(newMem, mem[i + 1:]...)
					}
					printf("%d\n", s)
					s++
					break
				}
			}
			if !allocated {
				printf("NULL\n")
			}
		case "erase":
			idx, _ := strconv.Atoi(nextWord())
			deleted := false
			for i, b := range mem {
				if idx == 0 {
					break
				}
				if b.i == idx {
					deleted = true
					b.i = 0
					if i > 0 && mem[i - 1].i == 0 {
						mem[i - 1].sz += b.sz
						mem = append(mem[:i], mem[i + 1:]...)
					} else if len(mem) > i + 1 && mem[i + 1].i == 0 {
						mem[i + 1].sz += b.sz
						mem = append(mem[:i], mem[i + 1:]...)
					}
				}
			}
			if !deleted {
				printf("ILLEGAL_ERASE_ARGUMENT\n")
			}
		}
	}
}

var lineScanner *Scanner
var wordScanner *Scanner

func init() {
	lineScanner = NewScanner(os.Stdin)
	wordScanner = NewScanner(strings.NewReader(""))
	wordScanner.Split(ScanWords)
}

func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = NewScanner(strings.NewReader(line))
		wordScanner.Split(ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
	empties      int       // Count of successive empty tokens.
	scanCalled   bool      // Scan has been called; buffer is in use.
	done         bool      // Scan has finished.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
// MaxScanTokenSize is the maximum size used to buffer a token
// unless the user provides an explicit buffer with Scan.Buffer.
// The actual maximum token size may be smaller as the buffer
// may need to include, for instance, a newline.
	MaxScanTokenSize = 2 * 1024 * 2014

	startBufSize = 4096 // Size of initial allocation for buffer.
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// ErrFinalToken is a special sentinel error value. It is intended to be
// returned by a Split function to indicate that the token being delivered
// with the error is the last token and scanning should stop after this one.
// After ErrFinalToken is received by Scan, scanning stops with no error.
// The value is useful to stop processing early or when it is necessary to
// deliver a final empty token. One could achieve the same behavior
// with a custom error value but providing one here is tidier.
// See the emptyFinalToken example for a use of this value.
var ErrFinalToken = errors.New("final token")

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
// Scan panics if the split function returns 100 empty tokens without
// advancing the input. This is a common error mode for scanners.
func (s *Scanner) Scan() bool {
	if s.done {
		return false
	}
	s.scanCalled = true
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		// If we've run out of data but have an error, give the split function
		// a chance to recover any remaining, possibly empty token.
		if s.end > s.start || s.err != nil {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				if err == ErrFinalToken {
					s.token = token
					s.done = true
					return true
				}
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				if s.err == nil || advance > 0 {
					s.empties = 0
				} else {
					// Returning tokens not advancing input at EOF.
					s.empties++
					if s.empties > 100 {
						panic("bufio.Scan: 100 empty tokens without progressing")
					}
				}
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is needed.
		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
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			// Guarantee no overflow in the multiplication below.
			const maxInt = int(^uint(0) >> 1)
			if len(s.buf) >= s.maxTokenSize || len(s.buf) > maxInt / 2 {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize == 0 {
				newSize = startBufSize
			}
			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
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0;; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				s.empties = 0
				break
			}
			loop++
			if loop > 10 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end - s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Buffer sets the initial buffer to use when scanning and the maximum
// size of buffer that may be allocated during scanning. The maximum
// token size is the larger of max and cap(buf). If max <= cap(buf),
// Scan will use this buffer only and do no allocation.
//
// By default, Scan uses an internal buffer and sets the
// maximum token size to MaxScanTokenSize.
//
// Buffer panics if it is called after scanning has started.
func (s *Scanner) Buffer(buf []byte, max int) {
	if s.scanCalled {
		panic("Buffer called after Scan")
	}
	s.buf = buf[0:cap(buf)]
	s.maxTokenSize = max
}

// Split sets the split function for the Scanner.
// The default split function is ScanLines.
//
// Split panics if it is called after scanning has started.
func (s *Scanner) Split(split SplitFunc) {
	if s.scanCalled {
		panic("Split called after Scan")
	}
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data) - 1] == '\r' {
		return data[0 : len(data) - 1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return start, nil, nil
}

package main

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

func isFitBetween(list []int, size int, amount int) (int,int) {
	counter := 0
	starter := 0

	for i := 0; i < size; i++ {
		if list[i] == 0 {
			counter++
		} else {
			starter = i + 1
			counter = 0
		}

		if counter == amount {
			return starter, i
		}
	}

	return -1,-1
}

func firstEmpty(list []int, size int) int {
	last := -1
	for i := size - 1; i >= 0; i-- {
		if list[i] == 0 {
			last = i
		} else {
			break
		}
	}
	return last
}

func mark(list []int, size int, number int, start int, amount int) []int {
	for i := start; i < start + amount; i++ {
		list[i] = number
	}
	return list
}

func delete(list []int, size int, number int) []int {
	resulter := false
	for i := 0; i < size; i++ {
		if list[i] == number {
			list[i] = 0
			resulter = true
		}
	}

	if number < 1 || resulter == false {
		fmt.Println("ILLEGAL_ERASE_ARGUMENT")
	}

	return list
}

func swap(list []int, size int, swap1 int, swap2 int) []int {
	temp := list[swap1]
	list[swap1] = list[swap2]
	list[swap2] = temp

	return list
}

func defragment(list []int, size int) []int {
	counter := true

	for counter {
		counter = false
		for i := 0; i < size - 1; i++ {
			if list[i] == 0 && list[i + 1] != 0 {
				list = swap(list, size, i, i+1)
				counter = true
			}
		}
	}

	return list
}

func main() {
	bio := bufio.NewReader(os.Stdin)
	input1, _, _ := bio.ReadLine()
	firstLineArray := strings.Split(string(input1), " ")

	lineCount,_ := strconv.Atoi(firstLineArray[0])
	size,_ := strconv.Atoi(firstLineArray[1])

	identifier := 0

	list := make([]int, size)

	inputList := make([]string, lineCount)

	for i := 0; i < size; i++ {
		list[i] = 0
	}

	for i := 0; i < lineCount; i++ {
		input, _, _ := bio.ReadLine()
		inputList[i] = string(input)
	}

	for i := 0; i < lineCount; i++ {
		inputSplit := strings.Split(inputList[i], " ")

		if inputSplit[0] == "alloc" {
			alloc, _ := strconv.Atoi(inputSplit[1])

			isFit1, isFit2 := isFitBetween(list, size, alloc)

			if isFit1 == -1 || isFit2 == -1 {
				fmt.Println("NULL")
			} else {
				identifier++
				list = mark(list, size, identifier, isFit1, alloc)
				fmt.Println(identifier)
			}
		} else if inputSplit[0] == "erase" {
			erase, _ := strconv.Atoi(inputSplit[1])

			list = delete(list, size, erase)
		} else if inputSplit[0] == "defragment" {
			list = defragment(list, size)
		}
	}
}

package main

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

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

	t, m := readTwoNums(reader)

	manager := NewManager(m)

	var buf bytes.Buffer

	for t > 0 {
		t--
		s, _ := reader.ReadBytes('\n')

		if s[0] == 'a' {
			var n int
			readInt(s, len("alloc "), &n)
			id := manager.Alloc(n)

			if id < 0 {
				buf.WriteString("NULL\n")
			} else {
				buf.WriteString(fmt.Sprintf("%d\n", id))
			}
		} else if s[0] == 'e' {
			var x int
			readInt(s, len("erase "), &x)
			ok := manager.Erase(x)
			if !ok {
				buf.WriteString("ILLEGAL_ERASE_ARGUMENT\n")
			}
		} else {
			manager.Defragment()
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

type Node struct {
	next *Node
	sz   int
	pos  int
	id   int
}

func NewNode(pos int, sz int) *Node {
	node := new(Node)
	node.pos = pos
	node.sz = sz
	return node
}

type Manager struct {
	free *Node
	used *Node
	mem  map[int]int
	p    int
	tot  int
}

func NewManager(m int) Manager {
	free := new(Node)
	free.next = NewNode(0, m)
	used := new(Node)
	mem := make(map[int]int)
	return Manager{free, used, mem, 0, m}
}

func (this *Manager) Alloc(n int) int {
	head := this.free

	for head.next != nil && head.next.sz < n {
		head = head.next
	}

	if head.next == nil {
		return -1
	}

	tmp := head.next
	pos := tmp.pos

	var tmp2 *Node

	if tmp.sz > n {
		tmp.sz -= n
		tmp.pos += n
		tmp2 = NewNode(pos, n)
	} else {
		head.next = tmp.next
		tmp2 = tmp
	}

	head = this.used

	for head.next != nil && head.next.pos < pos {
		head = head.next
	}

	tmp2.next = head.next

	head.next = tmp2

	this.p++
	this.mem[this.p] = pos
	tmp2.id = this.p

	return this.p
}

func (this *Manager) Erase(x int) bool {
	if pos, found := this.mem[x]; !found {
		return false
	} else {
		delete(this.mem, x)
		head := this.used
		//remove it from used
		for head.next != nil && head.next.pos < pos {
			head = head.next
		}

		if head.next == nil || head.next.pos > pos || head.next.id != x {
			return false
		}

		tmp := head.next
		head.next = tmp.next

		// put back as free
		head = this.free

		for head.next != nil && head.pos < pos {
			head = head.next
		}

		if head != this.free && head.pos+head.sz == pos {
			head.sz += tmp.sz
			return true
		}

		tmp.id = -1
		tmp.next = head.next
		head.next = tmp

		if tmp.next != nil && tmp.pos+tmp.sz == tmp.next.pos {
			tmp.sz += tmp.next.sz
			tmp.next = tmp.next.next
		}

		return true
	}
}

func (this *Manager) Defragment() {
	head := this.used
	var sz int

	for head.next != nil {
		cur := head.next
		cur.pos = sz
		sz += cur.sz
		head = head.next
	}

	if this.tot > sz {
		this.free.next = NewNode(sz, this.tot-sz)
	} else {
		this.free.next = nil
	}
}

package main

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

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

	t, m := readTwoNums(reader)

	manager := NewManager(m)

	var buf bytes.Buffer

	for t > 0 {
		t--
		s, _ := reader.ReadBytes('\n')

		if s[0] == 'a' {
			var n int
			readInt(s, len("alloc "), &n)
			id := manager.Alloc(n)

			if id < 0 {
				buf.WriteString("NULL\n")
			} else {
				buf.WriteString(fmt.Sprintf("%d\n", id))
			}
		} else if s[0] == 'e' {
			var x int
			readInt(s, len("erase "), &x)
			ok := manager.Erase(x)
			if !ok {
				buf.WriteString("ILLEGAL_ERASE_ARGUMENT\n")
			}
		} else {
			manager.Defragment()
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

type Node struct {
	next *Node
	sz   int
	pos  int
	id   int
}

func NewNode(pos int, sz int) *Node {
	node := new(Node)
	node.pos = pos
	node.sz = sz
	return node
}

type Manager struct {
	free *Node
	used *Node
	mem  map[int]int
	p    int
	tot  int
}

func NewManager(m int) Manager {
	free := new(Node)
	free.next = NewNode(0, m)
	used := new(Node)
	mem := make(map[int]int)
	return Manager{free, used, mem, 0, m}
}

func (this *Manager) Alloc(n int) int {
	head := this.free

	for head.next != nil && head.next.sz < n {
		head = head.next
	}

	if head.next == nil {
		return -1
	}

	tmp := head.next
	pos := tmp.pos

	var tmp2 *Node

	if tmp.sz > n {
		tmp.sz -= n
		tmp.pos += n
		tmp2 = NewNode(pos, n)
	} else {
		head.next = tmp.next
		tmp2 = tmp
	}

	head = this.used

	for head.next != nil && head.next.pos < pos {
		head = head.next
	}

	tmp2.next = head.next

	head.next = tmp2

	this.p++
	this.mem[this.p] = pos
	tmp2.id = this.p

	return this.p
}

func (this *Manager) Erase(x int) bool {
	if pos, found := this.mem[x]; !found {
		return true
	} else {
		head := this.used
		//remove it from used
		for head.next != nil && head.next.pos < pos {
			head = head.next
		}

		if head.next == nil || head.next.pos > pos || head.next.id != x {
			return false
		}

		tmp := head.next
		head.next = tmp.next

		// put back as free
		head = this.free

		for head.next != nil && head.pos < pos {
			head = head.next
		}

		if head != this.free && head.pos+head.sz == pos {
			head.sz += tmp.sz
			return true
		}

		tmp.id = -1
		tmp.next = head.next
		head.next = tmp

		if tmp.next != nil && tmp.pos+tmp.sz == tmp.next.pos {
			tmp.sz += tmp.next.sz
			tmp.next = tmp.next.next
		}

		return true
	}
}

func (this *Manager) Defragment() {
	head := this.used
	var sz int

	for head.next != nil {
		cur := head.next
		cur.pos = sz
		sz += cur.sz
		head = head.next
	}

	if this.tot > sz {
		this.free.next = NewNode(sz, this.tot-sz)
	} else {
		this.free.next = nil
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  x, o := getI(), getI()
  xPairs := x/2
  if xPairs > o {
    xPairs = o
  }
  x -= 2*xPairs
  o -= xPairs
  oFours := o/3
  if oFours > xPairs {
    oFours = xPairs
  }
  xPairs -= oFours
  o -= 3*oFours
  teams := xPairs + 2*oFours
  if x > 0 && o > 1 {
    x--
    o -= 2
    teams++
  }
  writer.WriteString(fmt.Sprintf("%d\n", teams))
}

package main

import (
	"strings"
	"fmt"
	"strconv"
	"errors"
	"io"
	"unicode/utf8"
	"bytes"
	"os"
)

type block struct {
	i, sz int
}
func main() {
	t, m, s := nextInt(), nextInt(), 1
	mem := make([]*block, 1)
	mem[0] = &block{0, m}
	for i := 0; i < t; i++ {
		op := nextWord()
		switch op {
		case "defragment":
			newMem := make([]*block, 0)
			sz := 0
			for _, b := range mem {
				if b.i != 0 {
					sz += b.sz
					newMem = append(newMem, b)
				}
			}
			if m - sz > 0 {
				mem = append(newMem, &block{0, m - sz})
			}
		case "alloc":
			sz, _ := strconv.Atoi(nextWord())
			allocated := false
			for i, b := range mem {
				if b.i == 0 && b.sz >= sz {
					allocated = true
					b.sz -= sz
					newMem := make([]*block, i)
					copy(newMem, mem)
					newMem = append(newMem, &block{s, sz})
					if b.sz > 0 {
						mem = append(newMem, mem[i:]...)
					} else {
						mem = append(newMem, mem[i + 1:]...)
					}
					printf("%d\n", s)
					s++
					break
				}
			}
			if !allocated {
				printf("NULL\n")
			}
		case "erase":
			idx, _ := strconv.Atoi(nextWord())
			deleted := false
			for i, b := range mem {
				if b.i == idx {
					deleted = true
					b.i = 0
					if i > 0 && mem[i - 1].i == 0 {
						mem[i - 1].sz += b.sz
						mem = append(mem[:i], mem[i + 1:]...)
					} else if len(mem) > i + 1 && mem[i + 1].i == 0 {
						mem[i + 1].sz += b.sz
						mem = append(mem[:i], mem[i + 1:]...)
					}
				}
			}
			if !deleted {
				printf("ILLEGAL_ERASE_ARGUMENT\n")
			}
		}
	}
}

var lineScanner *Scanner
var wordScanner *Scanner

func init() {
	lineScanner = NewScanner(os.Stdin)
	wordScanner = NewScanner(strings.NewReader(""))
	wordScanner.Split(ScanWords)
}

func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = NewScanner(strings.NewReader(line))
		wordScanner.Split(ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
	empties      int       // Count of successive empty tokens.
	scanCalled   bool      // Scan has been called; buffer is in use.
	done         bool      // Scan has finished.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
// MaxScanTokenSize is the maximum size used to buffer a token
// unless the user provides an explicit buffer with Scan.Buffer.
// The actual maximum token size may be smaller as the buffer
// may need to include, for instance, a newline.
	MaxScanTokenSize = 2 * 1024 * 2014

	startBufSize = 4096 // Size of initial allocation for buffer.
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// ErrFinalToken is a special sentinel error value. It is intended to be
// returned by a Split function to indicate that the token being delivered
// with the error is the last token and scanning should stop after this one.
// After ErrFinalToken is received by Scan, scanning stops with no error.
// The value is useful to stop processing early or when it is necessary to
// deliver a final empty token. One could achieve the same behavior
// with a custom error value but providing one here is tidier.
// See the emptyFinalToken example for a use of this value.
var ErrFinalToken = errors.New("final token")

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
// Scan panics if the split function returns 100 empty tokens without
// advancing the input. This is a common error mode for scanners.
func (s *Scanner) Scan() bool {
	if s.done {
		return false
	}
	s.scanCalled = true
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		// If we've run out of data but have an error, give the split function
		// a chance to recover any remaining, possibly empty token.
		if s.end > s.start || s.err != nil {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				if err == ErrFinalToken {
					s.token = token
					s.done = true
					return true
				}
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				if s.err == nil || advance > 0 {
					s.empties = 0
				} else {
					// Returning tokens not advancing input at EOF.
					s.empties++
					if s.empties > 100 {
						panic("bufio.Scan: 100 empty tokens without progressing")
					}
				}
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is needed.
		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
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			// Guarantee no overflow in the multiplication below.
			const maxInt = int(^uint(0) >> 1)
			if len(s.buf) >= s.maxTokenSize || len(s.buf) > maxInt / 2 {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize == 0 {
				newSize = startBufSize
			}
			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
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0;; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				s.empties = 0
				break
			}
			loop++
			if loop > 10 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end - s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Buffer sets the initial buffer to use when scanning and the maximum
// size of buffer that may be allocated during scanning. The maximum
// token size is the larger of max and cap(buf). If max <= cap(buf),
// Scan will use this buffer only and do no allocation.
//
// By default, Scan uses an internal buffer and sets the
// maximum token size to MaxScanTokenSize.
//
// Buffer panics if it is called after scanning has started.
func (s *Scanner) Buffer(buf []byte, max int) {
	if s.scanCalled {
		panic("Buffer called after Scan")
	}
	s.buf = buf[0:cap(buf)]
	s.maxTokenSize = max
}

// Split sets the split function for the Scanner.
// The default split function is ScanLines.
//
// Split panics if it is called after scanning has started.
func (s *Scanner) Split(split SplitFunc) {
	if s.scanCalled {
		panic("Split called after Scan")
	}
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data) - 1] == '\r' {
		return data[0 : len(data) - 1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return start, nil, nil
}

package main

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

func firstEmpty(list []int, size int) int {
	last := -1
	for i := size - 1; i >= 0; i-- {
		if list[i] == 0 {
			last = i
		} else {
			break
		}
	}
	return last
}

func mark(list []int, size int, number int, start int, amount int) []int {
	for i := start; i < start + amount; i++ {
		list[i] = number
	}
	return list
}

func delete(list []int, size int, number int) []int{
	for i := 0; i < size; i++ {
		if list[i] == number {
			list[i] = 0
		}
	}
	return list
}

func swap(list []int, size int, swap1 int, swap2 int) []int {
	temp := list[swap1]
	list[swap1] = list[swap2]
	list[swap2] = temp

	return list
}

func defragment(list []int, size int) []int {
	counter := true

	for counter {
		counter = false
		for i := 0; i < size - 1; i++ {
			if list[i] == 0 && list[i + 1] != 0 {
				list = swap(list, size, i, i+1)
				counter = true
			}
		}
	}

	return list
}

func main() {
	bio := bufio.NewReader(os.Stdin)
	input1, _, _ := bio.ReadLine()
	firstLineArray := strings.Split(string(input1), " ")

	lineCount,_ := strconv.Atoi(firstLineArray[0])
	size,_ := strconv.Atoi(firstLineArray[1])

	identifier := 0

	list := make([]int, size)

	inputList := make([]string, lineCount)

	for i := 0; i < size; i++ {
		list[i] = 0
	}

	for i := 0; i < lineCount; i++ {
		input, _, _ := bio.ReadLine()
		inputList[i] = string(input)
	}

	for i := 0; i < lineCount; i++ {
		inputSplit := strings.Split(inputList[i], " ")

		if inputSplit[0] == "alloc" {
			alloc, _ := strconv.Atoi(inputSplit[1])

			firstEmptyIndex := firstEmpty(list, size)

			if firstEmptyIndex == -1 || size - firstEmptyIndex < alloc {
				fmt.Println("NULL")
			} else {
				identifier++
				list = mark(list, size, identifier, firstEmptyIndex, alloc)
				fmt.Println(identifier)
			}
		} else if inputSplit[0] == "erase" {
			erase, _ := strconv.Atoi(inputSplit[1])

			list = delete(list, size, erase)
		} else if inputSplit[0] == "defragment" {
			list = defragment(list, size)
		}
	}
}

package main

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

func firstEmpty(list []int, size int) int {
	last := -1
	for i := size - 1; i >= 0; i-- {
		if list[i] == 0 {
			last = i
		} else {
			break
		}
	}
	return last
}

func mark(list []int, size int, number int, start int, amount int) []int {
	for i := start; i < start + amount; i++ {
		list[i] = number
	}
	return list
}

func delete(list []int, size int, number int) []int {
	resulter := false
	for i := 0; i < size; i++ {
		if list[i] == number {
			list[i] = 0
			resulter = true
		}
	}

	if resulter == false {
		fmt.Println("ILLEGAL_ERASE_ARGUMENT")
	}

	return list
}

func swap(list []int, size int, swap1 int, swap2 int) []int {
	temp := list[swap1]
	list[swap1] = list[swap2]
	list[swap2] = temp

	return list
}

func defragment(list []int, size int) []int {
	counter := true

	for counter {
		counter = false
		for i := 0; i < size - 1; i++ {
			if list[i] == 0 && list[i + 1] != 0 {
				list = swap(list, size, i, i+1)
				counter = true
			}
		}
	}

	return list
}

func main() {
	bio := bufio.NewReader(os.Stdin)
	input1, _, _ := bio.ReadLine()
	firstLineArray := strings.Split(string(input1), " ")

	lineCount,_ := strconv.Atoi(firstLineArray[0])
	size,_ := strconv.Atoi(firstLineArray[1])

	identifier := 0

	list := make([]int, size)

	inputList := make([]string, lineCount)

	for i := 0; i < size; i++ {
		list[i] = 0
	}

	for i := 0; i < lineCount; i++ {
		input, _, _ := bio.ReadLine()
		inputList[i] = string(input)
	}

	for i := 0; i < lineCount; i++ {
		inputSplit := strings.Split(inputList[i], " ")

		if inputSplit[0] == "alloc" {
			alloc, _ := strconv.Atoi(inputSplit[1])

			firstEmptyIndex := firstEmpty(list, size)

			if firstEmptyIndex == -1 || size - firstEmptyIndex < alloc {
				fmt.Println("NULL")
			} else {
				identifier++
				list = mark(list, size, identifier, firstEmptyIndex, alloc)
				fmt.Println(identifier)
			}
		} else if inputSplit[0] == "erase" {
			erase, _ := strconv.Atoi(inputSplit[1])

			list = delete(list, size, erase)
		} else if inputSplit[0] == "defragment" {
			list = defragment(list, size)
		}
	}
}

package main

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

func isFitBetween(list []int, size int, amount int) (int,int) {
	counter := 0
	starter := 0

	for i := 0; i < size; i++ {
		if list[i] == 0 {
			counter++
		} else {
			starter = i + 1
			counter = 0
		}

		if counter == amount {
			return starter, i
		}
	}

	return -1,-1
}

func firstEmpty(list []int, size int) int {
	last := -1
	for i := size - 1; i >= 0; i-- {
		if list[i] == 0 {
			last = i
		} else {
			break
		}
	}
	return last
}

func mark(list []int, size int, number int, start int, amount int) []int {
	for i := start; i < start + amount; i++ {
		list[i] = number
	}
	return list
}

func delete(list []int, size int, number int) []int {
	resulter := false
	for i := 0; i < size; i++ {
		if list[i] == number {
			list[i] = 0
			resulter = true
		}
	}

	if resulter == false {
		fmt.Println("ILLEGAL_ERASE_ARGUMENT")
	}

	return list
}

func swap(list []int, size int, swap1 int, swap2 int) []int {
	temp := list[swap1]
	list[swap1] = list[swap2]
	list[swap2] = temp

	return list
}

func defragment(list []int, size int) []int {
	counter := true

	for counter {
		counter = false
		for i := 0; i < size - 1; i++ {
			if list[i] == 0 && list[i + 1] != 0 {
				list = swap(list, size, i, i+1)
				counter = true
			}
		}
	}

	return list
}

func main() {
	bio := bufio.NewReader(os.Stdin)
	input1, _, _ := bio.ReadLine()
	firstLineArray := strings.Split(string(input1), " ")

	lineCount,_ := strconv.Atoi(firstLineArray[0])
	size,_ := strconv.Atoi(firstLineArray[1])

	identifier := 0

	list := make([]int, size)

	inputList := make([]string, lineCount)

	for i := 0; i < size; i++ {
		list[i] = 0
	}

	for i := 0; i < lineCount; i++ {
		input, _, _ := bio.ReadLine()
		inputList[i] = string(input)
	}

	for i := 0; i < lineCount; i++ {
		inputSplit := strings.Split(inputList[i], " ")

		if inputSplit[0] == "alloc" {
			alloc, _ := strconv.Atoi(inputSplit[1])

			isFit1, isFit2 := isFitBetween(list, size, alloc)

			if isFit1 == -1 || isFit2 == -1 {
				fmt.Println("NULL")
			} else {
				identifier++
				list = mark(list, size, identifier, isFit1, alloc)
				fmt.Println(identifier)
			}
		} else if inputSplit[0] == "erase" {
			erase, _ := strconv.Atoi(inputSplit[1])

			list = delete(list, size, erase)
		} else if inputSplit[0] == "defragment" {
			list = defragment(list, size)
		}
	}
}

package main

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

func firstEmpty(list []int, size int) int {
	last := -1
	for i := size - 1; i >= 0; i-- {
		if list[i] == 0 {
			last = i
		} else {
			break
		}
	}
	return last
}

func mark(list []int, size int, number int, start int, amount int) []int {
	for i := start; i < start + amount; i++ {
		list[i] = number
	}
	return list
}

func delete(list []int, size int, number int) []int {
	resulter := false
	for i := 0; i < size; i++ {
		if list[i] == number {
			list[i] = 0
			resulter = true
		}
	}

	if resulter == false {
		fmt.Println("ILLEGAL_ERASE_ARGUMENT")
	}

	return list
}

func swap(list []int, size int, swap1 int, swap2 int) []int {
	temp := list[swap1]
	list[swap1] = list[swap2]
	list[swap2] = temp

	return list
}

func getNextIdentifier(list []int, size int) int {
	maxValue := list[0]

	for i := 1; i < size; i++ {
		if maxValue < list[i] {
			maxValue = list[i]
		}
	}

	return maxValue + 1
}

func defragment(list []int, size int) []int {
	counter := true

	for counter {
		counter = false
		for i := 0; i < size - 1; i++ {
			if list[i] == 0 && list[i + 1] != 0 {
				list = swap(list, size, i, i+1)
				counter = true
			}
		}
	}

	return list
}

func main() {
	bio := bufio.NewReader(os.Stdin)
	input1, _, _ := bio.ReadLine()
	firstLineArray := strings.Split(string(input1), " ")

	lineCount,_ := strconv.Atoi(firstLineArray[0])
	size,_ := strconv.Atoi(firstLineArray[1])

	list := make([]int, size)

	inputList := make([]string, lineCount)

	for i := 0; i < size; i++ {
		list[i] = 0
	}

	for i := 0; i < lineCount; i++ {
		input, _, _ := bio.ReadLine()
		inputList[i] = string(input)
	}

	for i := 0; i < lineCount; i++ {
		inputSplit := strings.Split(inputList[i], " ")

		if inputSplit[0] == "alloc" {
			alloc, _ := strconv.Atoi(inputSplit[1])

			firstEmptyIndex := firstEmpty(list, size)

			if firstEmptyIndex == -1 || size - firstEmptyIndex < alloc {
				fmt.Println("NULL")
			} else {
				identifier := getNextIdentifier(list, size)
				list = mark(list, size, identifier, firstEmptyIndex, alloc)
				fmt.Println(identifier)
			}
		} else if inputSplit[0] == "erase" {
			erase, _ := strconv.Atoi(inputSplit[1])

			list = delete(list, size, erase)
		} else if inputSplit[0] == "defragment" {
			list = defragment(list, size)
		}
	}
}


You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,\dots, a_{2n}$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print "Yes" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case.

NoteIn the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.In the second, third and fifth test case, we can prove that there isn't any possible way.In the fourth test case, a possible way of splitting the set is $$$(2,3)$$$.

package main

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

func test() (a int)  {

	defer func() {
		a =+5
	}()

	a = 0

	return a
}

func binSearch(sim []int, findElement int) (int)  {

	low := 0
	hight := len(sim)

	for (low < hight) {
		mid := (low + hight)/2

		if sim[mid] == findElement {
			return sim[mid]
		}

		if findElement < sim[mid] {
			hight = mid
		}

		if findElement > sim[mid] {
			low = mid
		}

		fmt.Println("low ->", low)
		fmt.Println("hight ->", hight)
		fmt.Println("mid ->", mid)
		fmt.Println("------------")
	}

	return 0
}

func sortEasy(input []int, output *[]int)  {

	for i := 0; i < len(input); i++ {
		for j := 0; j < len(input)-1; j++ {
			if input[j] > input[j+1] {
				temp := input[j+1]
				input[j+1] = input[j]
				input[j] = temp
			}

			fmt.Println(input)
		}
	}

	copy(*output, input)
}

func main() {

	//simple := []int{5,100,2,94}

	//fmt.Println(binSearch(simple, 96))

	//sorted := make([]int, 100)
 	//sortEasy(simple, &sorted)
	//
	//fmt.Println(sorted)

 	scan := bufio.NewScanner(os.Stdin)

 	scan.Scan()

 	count, err := strconv.Atoi(scan.Text())

 	if err != nil {
 		log.Fatal(err)
	}

	for i := 0; i < count; i++ {
		scan.Scan()
		coup, err := strconv.Atoi(scan.Text())

		if err != nil {
			log.Fatal(err)
		}

		scan.Scan()

		elemets := strings.Split(scan.Text(), " ")

		an := 0

		for i := 0; i < coup * 2 ; i++ {
			t1 , _ := strconv.Atoi(elemets[i])

			if t1 % 2 == 0{
				an++
			} else {
				an--
			}

		}

		if an == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	_, err := fmt.Scan(&t)
	if err != nil {
		panic(err)
	}

	for i := 0; i < t; i++ {

		var n int
		_, err := fmt.Scan(&n)
		if err != nil {
			panic(err)
		}

		numbers := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			_, err := fmt.Scan(&numbers[i])
			if err != nil {
				panic(err)
			}
		}

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

func solve(numbers []int) bool {
	var odd = 0
	var not_odd = 0

	for _, v := range numbers {
		if v%2 == 0 {
			not_odd++
		} else {
			odd++
		}
	}

	return odd == not_odd
}

package main

import (
	"fmt"
)

func main() {
	var n, t, a, chc, nc int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j <= 2*n-1; j++ {
			fmt.Scan(&a)
			if a%2 == 0 {
				chc += 1
			} else {
				nc += 1
			}
		}
		if chc == nc {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
		chc = 0
		nc = 0
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, t, a, chc, nc int
	fmt.Scan(&t)
	arr := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j <= 2*n-1; j++ {
			fmt.Scan(&a)
			if a%2 == 0 {
				chc += 1
			} else {
				nc += 1
			}
		}
		if chc == nc {
			arr[i] = "Yes"
		} else {
			arr[i] = "No"
		}
		chc = 0
		nc = 0
	}
	for i := 0; i < t; i++ {
		fmt.Println(arr[i])
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var odds,evens int
		for j:=0;j<n;j++{
			var x,y int
			fmt.Scan(&x,&y)
			if x%2==0{
				evens++
			} else {
				odds++
			}
			if y%2==0{
				evens++
			} else {
				odds++
			}
		}
		if odds == evens {
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) (_b bool) {
		var n int
		Fscan(in, &n)
		a := make([]int, 2*n)
		c := [2]int{}
		for i := range a {
			Fscan(in, &a[i])
			c[a[i]&1]++
		}
		return c[0] == c[1]
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

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

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

        var t int
        fmt.Fscan(in, &t)

        for i := 0; i < t; i++ {
                n := 0
                var x int
                fmt.Fscan(in, &n)
                odd := 0
                for i := 0; i < 2*n; i++ {
                        fmt.Fscan(in, &x)
                        if x%2 == 1 {
                                odd++
                        }
}
                        if odd == n {
                                fmt.Fprintln(out, "YES")
                        } else {
                                fmt.Fprintln(out, "NO")
                        }
        }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for cas := 0; cas < t; cas++ {
		var n int
		fmt.Scan(&n)
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Scan(&a[i])
		}
		cnt := 0
		for i := 0; i < 2*n; i++ {
			if a[i]&1 == 1 {
				cnt++
			}
		}
		if cnt == n {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for count := 0; count < t; count++ {
		var n int
		fmt.Scan(&n)
		n += n
		a, b := 0, 0
		var x int
		for i := 0; i < n; i++ {
			fmt.Scan(&x)
			if x%2 == 0 {
				a++
			} else {
				b++
			}
		}
		if a == b {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		var odd, even int
		for i := 0; i < 2*n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			if temp%2 == 0 {
				even++
			} else {
				odd++
			}
		}

		if odd == even {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

func main() {
	var (
		t    int
		n    int
		asls []string
		a1   int
		a2   int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		a1, a2 = 0, 0
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		asls = strings.Split(scanner.Text(), " ")
		for j := 0; j < 2*n; j++ {
			temp, _ := strconv.Atoi(asls[j])
			if temp%2 == 0 {
				a1++
			} else {
				a2++
			}
		}
		if a2%n == 0 && (a2/n)%2 == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

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

func Solve(in []int) string {
	var even, odd int

	for _, v := range in {
		if v%2 == 0 {
			even++
		} else {
			odd++
		}
	}

	if even == odd {
		return "Yes"
	}

	return "No"
}

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

	for i := 0; i < n; i++ {
		_ = readInt(in)

		input := readArrInt(in)

		res := Solve(input)
		fmt.Printf("%s\n", res)
	}
}

package main

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

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

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

func solve() {
	var n int
	fmt.Fscan(input, &n)
	odd := 0
	for i := 0; i < 2*n; i++ {
		var val int
		fmt.Fscan(input, &val)
		if val & 1 == 1 { odd++ }
	}
	if odd == n {
		fmt.Fprintln(output, "YES")
	} else {
		fmt.Fprintln(output, "NO")
	}
}

package main

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

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

func solve(n int, a []int) string {
	var e int
	for _, x := range a {
		if x%2 == 0 {
			e++
		}
	}
	if e == n {
		return "Yes"
	}
	return "No"
}

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

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, 2*n)
		res := solve(A)
		if res {
			buf.WriteString("Yes\n")
		} else {
			buf.WriteString("No\n")
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(A []int) bool {
	var cnt int
	for i := 0; i < len(A); i++ {
		cnt += A[i] & 1
	}
	return cnt == len(A)/2
}

package main

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

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

func (in *CF1542A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1542A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1542A
 Date: 21/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1542/A
 Problem: CF1542A
**/
func (in *CF1542A) Run() {
	n := in.NextInt()
	for ; n > 0; n-- {
		t := in.NextInt()
		odd := 0
		even := 0
		for i := 0; i < 2*t; i++ {
			num := in.NextInt()
			if num %2 == 0{
				even++
			} else {
				odd++
			}
		}
		if odd == even && odd == t {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

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

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

package main

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

func solve(n int32, arr []int32) string {
	evens := int32(0)
	for _, value := range arr {
		if value%2 == 0 {
			evens++
		}
	}
	if evens == n {
		return "YES"
	} else {
		return "NO"
	}
}

func arrayScanf(in *bufio.Reader, n int32, arr *[]int32) {
	m := int32(0)
	for i := int32(0); i < 2*n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		*arr = append(*arr, m)
	}
	fmt.Fscanf(in, "\n")
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		arr := []int32{}
		fmt.Fscanf(in, "%d\n", &n)
		arrayScanf(in, n, &arr)
		fmt.Fprintf(out, "%s\n", solve(n, arr))
		tt--
	}
	out.Flush()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, curr, m int
		fmt.Scan(&n)
		for j := 0; j < 2*n; j++ {
			fmt.Scan(&curr)
			if curr%2 == 0 {
				m++
			} else {
				m--
			}
		}
		if m == 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		var odd, even int
		for i := 0; i < 2*n; i++ {
			var m int
			fmt.Fscan(input, &m)
			if m%2 == 0 {
				even++
			} else {
				odd++
			}
		}
		if even == odd {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARRAY := make([]int64, 2*n)

		for i := 0; i < 2*n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		var count int = 0

		for _, element := range ARRAY {
			if element % 2 == 0 {
				count += 1
			}
		}

		if count == n {
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}

	}
}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n*2)
		cnt := 0
		for i := range a {
			Fscan(in, &a[i])
			if a[i]%2 == 1 {
				cnt++
			}
		}
		if cnt == n {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
	var T int
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

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

package main

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

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

	var t int
	fmt.Fscan(r, &t)

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

		a := make([]int, 2 * n)
		for j := 0; j < 2 * n; j++ {
			fmt.Fscan(r, &a[j])
		}

		solve(a, n)
	}
}

func solve(a []int, n int) {
	var odd int
	var even int

	for  i := 0; i < 2 * n; i++ {
		if a[i] % 2 == 0 {
			even++
		} else {
			odd++
		}
	}

	if odd == even {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func solver() {
	var n = 0
	var x int
	fmt.Scan(&n)
	odd := 0
	for i := 0; i < 2*n; i++ {
		fmt.Scan(&x)
		if x % 2 == 1 {
			odd++
		}
	}

	if odd == n {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solver()
	}
}

package main

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

// четных и нечетных должно быть одинаково
// повторяющихся должно быть не больше количества пар
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())

		scanner.Scan()
		input := scanner.Text()

		inputList := make([]int, 0, 100)
		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		var sum, even, odd int
		var repeatedCount = make(map[int]int, len(inputList))
		for _, s := range inputList {
			sum += s
			if s%2 == 0 {
				odd++
			} else {
				even++
			}

			repeatedCount[s]++
		}
		var mostRepeated int
		for _, c := range repeatedCount {
			if c > mostRepeated {
				mostRepeated = c
			}
		}

		if mostRepeated > n || odd != even {
			fmt.Println("No")
			continue
		}

		if (n%2 == 0 && sum%2 != 0) || (n%2 != 0 && sum%2 == 0) {
			fmt.Println("No")
			continue
		}

		fmt.Println("Yes")
	}
}

package main

import "fmt"

func main() {
	var t int
	ans := []bool{}
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		var read int
		even, odd := 0, 0
		for i := 0; i < 2*n; i++ {
			fmt.Scan(&read)
			if read%2 == 0 {
				even++
			} else {
				odd++
			}
		}
		if even == odd {
			ans = append(ans, true)
		} else {
			ans = append(ans, false)
		}
		t--
	}
	for _, v := range ans {
		if v {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import "fmt"

func main(){
	tt := 0
	fmt.Scan(&tt)
	for j := 0; j < tt; j++ {
		n := 0
		fmt.Scan(&n)
		array := make([]int, n*2)
		chet := 0
		nechet := 0
		for i := 0; i < n*2; i++ {
			fmt.Scan(&array[i])
			if array[i] % 2 == 0 {
				chet++
			} else {
				nechet++
			}
		}
		if chet == nechet {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := sint64s(n * 2)
		printf("%s\n", sol(a))
	}
}

func sol(a []int64) string {
	p := [2]int64{0, 0}
	for i := range a {
		p[a[i]&1]++
	}
	if p[0] == p[1] {
		return "Yes"
	}
	return "No"
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
	for ;t>0;t-- {
		nechet := 0
		n := io.ReadInt()
		a := io.ReadIntSlice(n * 2)
		for _, v := range a {
			if v % 2 == 1 {
				nechet++
			}
		}
		if nechet == n {
			io.Println("Yes")
		} else {
			io.Println("No")
		}
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func possible(nums []int) bool {
	even := 0
	odd := 0

	for _, num := range nums {
		if num%2 == 0 {
			even += 1
		} else {
			odd += 1
		}
	}
	return even == odd
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		n := stdin.Int()
		nums := stdin.Ints(2 * n)

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

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n := io.NextInt()
			v := 0
			for i := 0; i < 2*n; i++ {
				x := io.NextInt()
				v += (x & 1)
			}
			if v == n {
				io.Println("Yes")
			} else {
				io.Println("No")
			}
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func test() (a int)  {

	defer func() {
		a =+5
	}()

	a = 0

	return a
}

func binSearch(sim []int, findElement int) (int)  {

	low := 0
	hight := len(sim)

	for (low < hight) {
		mid := (low + hight)/2

		if sim[mid] == findElement {
			return sim[mid]
		}

		if findElement < sim[mid] {
			hight = mid
		}

		if findElement > sim[mid] {
			low = mid
		}

		fmt.Println("low ->", low)
		fmt.Println("hight ->", hight)
		fmt.Println("mid ->", mid)
		fmt.Println("------------")
	}

	return 0
}

func sortEasy(input []int, output *[]int)  {

	for i := 0; i < len(input); i++ {
		for j := 0; j < len(input)-1; j++ {
			if input[j] > input[j+1] {
				temp := input[j+1]
				input[j+1] = input[j]
				input[j] = temp
			}

			fmt.Println(input)
		}
	}

	copy(*output, input)
}

func main() {

	//simple := []int{5,100,2,94}

	//fmt.Println(binSearch(simple, 96))

	//sorted := make([]int, 100)
 	//sortEasy(simple, &sorted)
	//
	//fmt.Println(sorted)

 	scan := bufio.NewScanner(os.Stdin)

 	scan.Scan()

 	count, err := strconv.Atoi(scan.Text())

 	if err != nil {
 		log.Fatal(err)
	}

	for i := 0; i < count; i++ {
		scan.Scan()
		//coup, err := strconv.Atoi(scan.Text())

		if err != nil {
			log.Fatal(err)
		}

		scan.Scan()

		elemets := strings.Split(scan.Text(), " ")

		state := true
		for i := 0; i <= len(elemets)-1; i = i+2 {
			t1 , _ := strconv.Atoi(elemets[i])
			t2, _ := strconv.Atoi(elemets[i+1])

			sum := t1+t2

			if sum % 2 == 0 {
				fmt.Println("NO")
				state = false
				break
			}
		}

		if state {
			fmt.Println("YES")
		}

	}
}

package main

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

func test() (a int)  {

	defer func() {
		a =+5
	}()

	a = 0

	return a
}

func binSearch(sim []int, findElement int) (int)  {

	low := 0
	hight := len(sim)

	for (low < hight) {
		mid := (low + hight)/2

		if sim[mid] == findElement {
			return sim[mid]
		}

		if findElement < sim[mid] {
			hight = mid
		}

		if findElement > sim[mid] {
			low = mid
		}

		fmt.Println("low ->", low)
		fmt.Println("hight ->", hight)
		fmt.Println("mid ->", mid)
		fmt.Println("------------")
	}

	return 0
}

func sortEasy(input []int, output *[]int)  {

	for i := 0; i < len(input); i++ {
		for j := 0; j < len(input)-1; j++ {
			if input[j] > input[j+1] {
				temp := input[j+1]
				input[j+1] = input[j]
				input[j] = temp
			}

			fmt.Println(input)
		}
	}

	copy(*output, input)
}

func main() {

	//simple := []int{5,100,2,94}

	//fmt.Println(binSearch(simple, 96))

	//sorted := make([]int, 100)
 	//sortEasy(simple, &sorted)
	//
	//fmt.Println(sorted)

 	scan := bufio.NewScanner(os.Stdin)

 	scan.Scan()

 	count, err := strconv.Atoi(scan.Text())

 	if err != nil {
 		log.Fatal(err)
	}

	for i := 0; i < count; i++ {
		scan.Scan()
		coup, err := strconv.Atoi(scan.Text())

		if err != nil {
			log.Fatal(err)
		}

		scan.Scan()

		elemets := strings.Split(scan.Text(), " ")

		for i := 0; i <= coup; i = i+2 {
			t1 , _ := strconv.Atoi(elemets[i])
			t2, _ := strconv.Atoi(elemets[i+1])

			sum := t1+t2

			if sum % 2 == 0 {
				fmt.Println("NO")
				return
			}
		}

		fmt.Println("YES")

	}
}

package main

import (
	"fmt"
)

func main() {
	var n, t, a, chc, nc int
	fmt.Scanln(&t)
	arr := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)
		for j := 0; j <= 2*n-1; j++ {
			fmt.Scan(&a)
			if a%2 == 0 {
				chc += 1
			} else {
				nc += 1
			}
		}
		if chc == nc {
			arr[i] = "Yes"
		} else {
			arr[i] = "No"
		}
		chc = 0
		nc = 0
	}
	for i := 0; i < t; i++ {
		fmt.Println(arr[i])
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		for j:=0;j<n;j++{
			var x,y int
			fmt.Scan(&x,&y)
			if (x+y)%2 == 0 {
				fmt.Println("NO")
				goto out
			}
		}
		fmt.Println("YES")
		out:
	}
}

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

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

        var t int
        fmt.Fscan(in, &t)

        for i := 0; i < t; i++ {
                n := 0
                var x int
                fmt.Fscan(in, &n)
                odd := 0
                for i := 0; i < 2*n; i++ {
                        fmt.Fscan(in, &x)
                        if x%2 == 1 {
                                odd++
                        }
                        if odd == n {
                                fmt.Fprintln(out, "YES")
                        } else {
                                fmt.Fprintln(out, "NO")
                        }
                }
        }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for cas := 0; cas < t; cas++ {
		var n int
		fmt.Scan(n)
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Scan(&a[i])
		}
		cnt := 0
		for i := 0; i < 2*n; i++ {
			if a[i]&1 == 1 {
				cnt++
			}
		}
		if cnt == n {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for count := 0; count < t; count++ {
		var n int
		fmt.Scan(&n)
		n += n
		a, b := 0, 0
		var x int
		for i := 0; i < n; i++ {
			fmt.Scan(&x)
			if x%2 == 0 {
				a++
			} else {
				b++
			}
		}
		if a == b {
			fmt.Println("Yes")
		} else {
			fmt.Print("No")
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		var odd, even int
		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			if temp%2 == 0 {
				even++
			} else {
				odd++
			}
		}

		if odd == even {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}