package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(stdin, &n)

	var a = make([]int, n)
	var stack = make([]int, 0)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &a[i])
		a[i] &= 1

		stack = append(stack, a[i])
		if len(stack) > 1 && stack[len(stack)-1] == stack[len(stack)-2] {
			stack = stack[:len(stack)-2]
		}
	}
	if len(stack) <= 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func solve(mat []bool)bool  {
//	fmt.Println("solve:",mat)
	len := len(mat)
	stack := make([]bool,len)
	var front int = 0
	for i:=0;i < len&&front <= len/2;i++{
		if front == 0{
			stack[front] = mat[i]
			front++
			continue
		}
		if stack[front-1] != mat[i]{
			front--
		}else{
			stack[front]=mat[i]
			front++
		}
	}
	if front > 0{
		return false
	}else{
		return true
	}
}
func oddOrEven(v []bool)[]bool {
	len := len(v)
	for i := 0;i < len;i++{
		if v[i] == true{
			v[i] = false
		}else{
			v[i] = true
		}
	}
	return v
}
func process(v []bool)[]bool  {
//	fmt.Println("v:",v)
	res := make([]bool,0)
	cnt := 0
	len := len(v)
	for i:=0;i <= len;i++{
		if cnt>0&&( i == len || v[i] == false){
			if (cnt&1)==1{
				if (i&1)==1{
					res = append(res,true)
				}else{
					res = append(res,false)
				}
			}
			cnt = 0
		}
		if i < len&&v[i]{
			cnt++
		}
	}
//	fmt.Println("res:",res)
	return res
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	flag := make([]bool,n)
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscanf(buf, "%d",&v)
		flag[i] = false
		if (v&1)==1{
			flag[i] = true
		}
	}
	pv := process(flag)
	ppv := process(oddOrEven(flag))
	if solve(pv) || solve(ppv){
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}

/*
4 2
1 2
3 4
2 0

5 4
1 2
3 4
4 5
5 3
5 1
1 2
*/

package main

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

func main() {
	io := newIO()
	defer io.out.Flush()

	n := io.nextInt()
	a := io.nextArr(n)
	var s stack
	for i := 0; i < n; i++ {
		s = s.clr()
		s = s.Push(a[i] % 2)
	}
	s = s.clr()
	if len(s) <= 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func (s stack) clr() stack {
	var first, second int
	for len(s) >= 2 {
		s, first = s.Pop()
		s, second = s.Pop()
		if first != second {
			s = s.Push(second)
			s = s.Push(first)
			return s
		}
	}
	return s
}

type stack []int

func (s stack) Push(v int) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, int) {
	l := len(s)
	return  s[:l-1], s[l-1]
}

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

type io struct {
	inp *bufio.Scanner
	out *bufio.Writer
}

func newIO() io {
	sc := io{
		inp : bufio.NewScanner(os.Stdin),
		out : bufio.NewWriter(os.Stdout),
	}
	sc.inp.Split(bufio.ScanWords)
	return sc
}
func (sc io) nextArr(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = sc.nextInt()
	}
	return a
}
func (sc io) nextString() string {
	sc.inp.Scan()
	return sc.inp.Text();
}

func (sc io) nextInt64() int64 {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int64(v)
}
func (sc io) nextInt() int {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int(v)
}

package main

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

type block struct {
	n int64
	h int64
}

var n int
var x int64
var wall []block

func Abs(n int64) int64 {
	if n < 0 {
		return n * -1
	}
	return n
}
func Max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func NewBlock(n, h int64) block {
	return block{n: n, h: h}
}
func Swap(a, b block) (block, block) {
	return b, a
}

func Combine(a, b block) block {
	var res = block{n: a.n + b.n, h: Max(a.h, b.h)}

	if Abs(a.h-b.h)%2 == 0 {
		return res
	}
	if a.n%2 == 0 || b.n%2 == 0 {
		if a.n%2 == 1 {
			a, b = Swap(a, b)
		}
		if a.h > b.h {
			res.h++
			return res
		}
		return res
	}

	res.n = -1
	return res
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	// stdin = bufio.NewReader(os.Stdin)

	fmt.Fscan(stdin, &n)
	wall = make([]block, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x)
		wall[i].n = 1
		wall[i].h = x
	}

	var found = true
	for found {
		found = false
		var newwall = []block{}
		if len(wall) == 1 {
			break
		}
		for i := 0; i < len(wall); i++ {
			if i == len(wall)-1 {
				newwall = append(newwall, wall[i])
			} else {
				var tmp = Combine(wall[i], wall[i+1])
				if tmp.n != -1 {
					i++
					newwall = append(newwall, tmp)
					found = true
				} else {
					newwall = append(newwall, wall[i])
				}
			}
		}
		if len(wall) == len(newwall) {
			break
		}
		wall = newwall
		// fmt.Println("Combined", wall)
	}

	if len(wall) != 1 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

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

type block struct {
    n int64
    h int64
}

var n int
var x int64
var wall []block

func Abs (n int64) int64 {
    if n < 0 {
        return n * -1
    }
    return n
}
func Max (a, b int64) int64 {
    if a > b {
        return a
    }
    return b
}

func Combine(a, b block) block {
    var res = block {n: a.n + b.n, h: Max(a.h, b.h) }
    if a.n % 2 == 0 || b.n % 2 == 0 {
        // Cot chan, ghep sao cung okie
        return res
    } else if a.n == 1 && b.n == 1 {
        if Abs(a.h - b.h) % 2 == 0 {
            return res
        }
    } else if Abs(a.h - b.h) % 2 == 0 {
        return res
    }
    res.n = -1
    res.h = 0
    return res
}

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)

    fmt.Fscan(stdin, &n)
    wall = make([]block, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(stdin, &x)
        wall[i].n = 1
        wall[i].h = x
    }

    b := make([]block, n)
    for i:= 0; i < n-1; i++ {
        var tmp = Combine(wall[i], wall[i + 1])
        if tmp.n != -1 {
            b[i] = tmp
        } else {
            b[i] = wall[i]
        }
    }

    var found = true
    b = wall
    for found {
        found = false
        for i := 0; i < n; {
            var j = int64(i) + b[i].n
            if j >= int64(n) {
                break
            }
            var tmp = Combine(b[i], b[j])

            if tmp.n != -1 {
                found = true
                b[i] = tmp
            } else {
                i++
            }
        }
        // fmt.Println("Combined", b)
    }

    if b[0].n == int64(n) {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

type block struct {
    n int64
    h int64
}

var n int
var x int64
var wall []block

func Abs (n int64) int64 {
    if n < 0 {
        return n * -1
    }
    return n
}
func Max (a, b int64) int64 {
    if a > b {
        return a
    }
    return b
}

func Combine(a, b block) block {
    var res = block {n: a.n + b.n, h: Max(a.h, b.h) }
    if a.n % 2 == 0 || b.n % 2 == 0 {
        // Cot chan, ghep sao cung okie
        return res
    } else if a.n == 1 && b.n == 1 {
        if Abs(a.h - b.h) % 2 == 0 {
            return res
        }
    } else if Abs(a.h - b.h) % 2 == 0 {
        return res
    }
    res.n = -1
    return res
}

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)

    fmt.Fscan(stdin, &n)
    wall = make([]block, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(stdin, &x)
        wall[i].n = 1
        wall[i].h = x
    }

    var found = true
    for found {
        found = false
        var newwall = []block{}
        if len(wall) == 1 {
            break
        }
        for i := 0; i < len(wall); i++ {
            if i == len(wall) - 1 {
                newwall = append(newwall, wall[i])
            } else {
                var tmp = Combine(wall[i], wall[i + 1])
                if tmp.n != -1 {
                    i++
                    newwall = append(newwall, tmp)
                    found = true
                } else {
                    newwall = append(newwall, wall[i])
                }
            }
        }

        wall = newwall
        // fmt.Println("Combined", wall)
    }

    if len(wall) != 1 {
        fmt.Println("NO")
    } else {
        fmt.Println("YES")
    }
}

package main

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

type block struct {
    n int64
    h int64
}

var n int
var x int64
var wall []block

func Abs (n int64) int64 {
    if n < 0 {
        return n * -1
    }
    return n
}
func Max (a, b int64) int64 {
    if a > b {
        return a
    }
    return b
}

func Combine(a, b block) block {
    var res = block {n: a.n + b.n, h: Max(a.h, b.h) }
    if a.n % 2 == 0 || b.n % 2 == 0 {
        // Cot chan, ghep sao cung okie
        return res
    } else if a.n == 1 && b.n == 1 {
        if Abs(a.h - b.h) % 2 == 0 {
            return res
        }
    } else if Abs(a.h - b.h) % 2 == 0 {
        return res
    }
    res.n = -1
    return res
}

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)

    fmt.Fscan(stdin, &n)
    wall = make([]block, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(stdin, &x)
        wall[i].n = 1
        wall[i].h = x
    }

    b := make([]block, n)
    for i:= 0; i < n-1; i++ {
        var tmp = Combine(wall[i], wall[i + 1])
        if tmp.n != -1 {
            b[i] = tmp
        } else {
            b[i] = wall[i]
        }
    }

    var found = true
    b = wall
    for found {
        found = false
        for i := 0; i < n; {
            var j = int64(i) + b[i].n
            if j >= int64(n) {
                break
            }
            var tmp = Combine(b[i], b[j])

            if tmp.n != -1 {
                found = true
                b[i] = tmp
                i = int(j)
            } else {
                i++
            }
        }
        // fmt.Println("Combined", b)
    }

    if b[0].n == int64(n) {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

func main() {
	io := newIO()
	defer io.out.Flush()

	n := io.nextInt()
	a := io.nextArr(n)
	mx := 0
	for _, v := range a { mx = max(mx, v) }

main : for add := 0; add <= 3; add++ {
	arr := make([]int, n)
	for i, v := range a {
		arr[i] = (mx + add - v)
		if arr[i] % 2 == 0 { arr[i] = 2 } else { arr[i] = 1 }
	}
inner : for i, v := range arr {
	if v == 0 { continue }
	if v == 1 {
		if i >= 1 && arr[i - 1] == 1 {
			arr[i] = 0
			arr[i - 1] = 0
			continue inner
		}
		if i <= n - 2 && arr[i + 1] == 1 {
			arr[i] = 0
			arr[i + 1] = 0
			continue inner
		}
		if i <= n - 3 && arr[i + 1] == 2 && arr[i + 2] == 2 {
			arr[i] = 0
			arr[i + 1] = 0
			arr[i + 2] = 1
			continue inner
		}
		continue main
	} else {
		arr[i] = 0
	}
}

	io.out.WriteString("YES\n")
	return
}

	io.out.WriteString("NO\n")
}

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

type io struct {
	inp *bufio.Scanner
	out *bufio.Writer
}

func newIO() io {
	sc := io{
		inp : bufio.NewScanner(os.Stdin),
		out : bufio.NewWriter(os.Stdout),
	}
	sc.inp.Split(bufio.ScanWords)
	return sc
}
func (sc io) nextArr(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = sc.nextInt()
	}
	return a
}
func (sc io) nextString() string {
	sc.inp.Scan()
	return sc.inp.Text();
}

func (sc io) nextInt64() int64 {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int64(v)
}
func (sc io) nextInt() int {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int(v)
}

package main

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

func main() {
	io := newIO()
	defer io.out.Flush()

	n := io.nextInt()
	a := io.nextArr(n)
	mx := 0
	for _, v := range a { mx = max(mx, v) }

	main : for add := 0; add <= 3; add++ {
		arr := make([]int, n)
		for i, v := range a {
			arr[i] = (mx + add - v)
			if arr[i] != 0 {
				if arr[i] % 2 == 0 { arr[i] = 2 } else { arr[i] = 1 }
			}
		}
		inner : for i, v := range arr {
			if v == 0 { continue }
			if v == 1 {
				if i >= 1 && arr[i - 1] == 1 {
					arr[i] = 0
					arr[i - 1] = 0
					continue inner
				}
				if i <= n - 2 && arr[i + 1] == 1 {
					arr[i] = 0
					arr[i + 1] = 0
					continue inner
				}
				if i <= n - 3 && arr[i + 1] == 2 && arr[i + 2] == 2 {
					arr[i] = 0
					arr[i + 1] = 0
					arr[i + 2] = 1
					continue inner
				}
				continue main
			} else {
				arr[i] = 0
			}
		}

		io.out.WriteString("YES\n")
		return
	}

	io.out.WriteString("NO\n")
}

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

type io struct {
	inp *bufio.Scanner
	out *bufio.Writer
}

func newIO() io {
	sc := io{
		inp : bufio.NewScanner(os.Stdin),
		out : bufio.NewWriter(os.Stdout),
	}
	sc.inp.Split(bufio.ScanWords)
	return sc
}
func (sc io) nextArr(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = sc.nextInt()
	}
	return a
}
func (sc io) nextString() string {
	sc.inp.Scan()
	return sc.inp.Text();
}

func (sc io) nextInt64() int64 {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int64(v)
}
func (sc io) nextInt() int {
	v, _ := strconv.ParseInt(sc.nextString(), 10, 64)
	return int(v)
}


package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

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

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

func main() {
	defer w.Flush()
	var a int
	for I(&a) == nil {
		solve(a)
	}
}

func solve(a int) {
	var b, c, m int
	I(&b, &c, &m)
	mm := make(arr, m)
	for i := 0; i < m; i++ {
		var s string
		I(&mm[i][0], &s)
		if s == "USB" {
			mm[i][1] = 1
		}
	}
	sort.Sort(mm)
	ans := 0
	amount := uint64(0)
	for i := range mm {
		if mm[i][1] == 1 {
			if a > 0 {
				a--
				ans++
				amount += mm[i][0]
			} else if c > 0 {
				c--
				ans++
				amount += mm[i][0]
			}
		} else {
			if b > 0 {
				b--
				ans++
				amount += mm[i][0]
			} else if c > 0 {
				c--
				ans++
				amount += mm[i][0]
			}
		}
	}
	O(ans, amount, "\n")
}

type arr [][2]uint64

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

package main

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

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

func ReadInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

type mouse struct {
	price int
	mType string
}

func main() {
	defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    usb, ps2, b := ReadInt(), ReadInt(), ReadInt()

    m := ReadInt()

    v := make([]mouse, m)

    for i := 0; i < m; i++ {
    	var mo mouse
    	mo.price = ReadInt()
    	scanner.Scan()
    	mo.mType = scanner.Text()
    	v[i] = mo
    }

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

   	qt := 0
   	total := int64(0)

   	for _,elem := range v {

   		if elem.mType == "USB" {
   			if usb > 0 {
   				usb--
   				qt++
   				total += int64(elem.price)
   			} else if b > 0 {
   				b--
   				qt++
   				total += int64(elem.price)
   			}
   		} else {
   			if ps2 > 0 {
   				ps2--
   				qt++
   				total += int64(elem.price)
   			} else if b > 0 {
   				b--
   				qt++
   				total += int64(elem.price)
   			}
   		}
   	}

	writer.WriteString(strconv.Itoa(qt))
	writer.WriteString(" ")
	writer.WriteString(strconv.FormatInt(total, 10))
	writer.WriteString("\n")

}

package main

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

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

func ReadInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

type mouse struct {
	price int
	mType string
}

func main() {
	defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    usb, ps2, b := ReadInt(), ReadInt(), ReadInt()

    m := ReadInt()

    var v []mouse

    for ; m > 0; m-- {
    	var mo mouse
    	mo.price = ReadInt()
    	scanner.Scan()
    	mo.mType = scanner.Text()
    	v = append(v, mo)
    }

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

   	qt := 0
   	total := int64(0)

   	for _,elem := range v {

   		if elem.mType == "USB" {
   			if usb > 0 {
   				usb--
   				qt++
   				total += int64(elem.price)
   			} else if b > 0 {
   				b--
   				qt++
   				total += int64(elem.price)
   			}
   		} else {
   			if ps2 > 0 {
   				ps2--
   				qt++
   				total += int64(elem.price)
   			} else if b > 0 {
   				b--
   				qt++
   				total += int64(elem.price)
   			}
   		}
   	}

	writer.WriteString(strconv.Itoa(qt))
	writer.WriteString(" ")
	writer.WriteString(strconv.FormatInt(total, 10))
	writer.WriteString("\n")

}

package main

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

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

const (
    usb = iota
    ps2
)

type mouse struct {
    price int64
    port  int
}

type byPort []mouse

func (a byPort) Len() int {
    return len(a)
}

func (a byPort) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a byPort) Less(i, j int) bool {
    return a[i].port < a[j].port || (a[i].port == a[j].port && a[i].price < a[j].price)
}

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

    // your code here
    var a, b, c int
    fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
    var m int
    fmt.Fscanf(in, "%d\n", &m)
    portCodes := map[string]int{
        "USB": usb,
        "PS/2": ps2,
    }
    usbCount := 0
    mice := make([]mouse, m)
    for i := 0; i < m; i++ {
        var port string
        fmt.Fscanf(in, "%d %s\n", &(mice[i].price), &port)
        mice[i].port = portCodes[port]
        if mice[i].port == usb {
            usbCount++
        }
    }
    sort.Sort(byPort(mice))

    usbIdx, ps2Idx := 0, usbCount
    count, cost := 0, int64(0)
    for i := 0; i < a && usbIdx < usbCount; i, count, usbIdx = i+1, count+1, usbIdx+1 {
        cost += mice[usbIdx].price
    }
    for i := 0; i < b && ps2Idx < m; i, count, ps2Idx = i+1, count+1, ps2Idx+1 {
        cost += mice[ps2Idx].price
    }
    for i := 0; i < c && (usbIdx < usbCount || ps2Idx < m); i, count = i+1, count+1 {
        var cheapPrice int64 = 10000000001
        var idx *int
        if usbIdx < usbCount && mice[usbIdx].price < cheapPrice {
            cheapPrice = mice[usbIdx].price
            idx = &usbIdx
        }
        if ps2Idx < m && mice[ps2Idx].price < cheapPrice {
            cheapPrice = mice[ps2Idx].price
            idx = &ps2Idx
        }
        cost += cheapPrice
        *idx++
    }

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

package main

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

type Mouse struct {
	Price int64
	IsUsb bool
}

func solve() {
	a := readInt()
	b := readInt()
	c := readInt()
	m := readInt()
	items := make([]Mouse, m)
	for i := 0; i < m; i++ {
		items[i] = Mouse{readInt64(), parseType(readString())}
	}
	sort.Sort(ByPrice(items))
	total := 0
	sum := int64(0)
	for i := 0; i < m; i++ {
		item := items[i]
		if item.IsUsb {
			if a > 0 {
				a--
				total++
				sum += item.Price
			} else if c > 0 {
				c--
				total++
				sum += item.Price
			}
		} else {
			if b > 0 {
				b--
				total++
				sum += item.Price
			} else if c > 0 {
				c--
				total++
				sum += item.Price
			}
		}
	}
	fmt.Printf("%d %d\n", total, sum)
}

type ByPrice []Mouse

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

func parseType(name string) bool {
	if name == "USB" {
		return true
	}
	return false
}

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 max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

// Codeforces 774 C done
package main

import (
"bufio"
"fmt"
"strings"
"strconv"
	"os"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var a,b,c,m int
var mCost []int
var usbPs []bool
var nComp int
var totCost int64

func readData() {
	in = bufio.NewReader(os.Stdin)
	a,b,c,_,_ = readFive()
	m,_,_,_,_ = readFive()
	usbPs = make([]bool, m)
	mCost = make([]int, m)
	for i:=0; i<m; i++ {
        s, err := in.ReadString('\n')
        if err != nil {
            fmt.Println("read mouse failure", err)
            panic(err)
        }
        ss := strings.Split(strings.Trim(s, " \n\r"), " ")
        mCost[i],_ = strconv.Atoi(ss[0])
        if ss[1][0] == 'U' {
            usbPs[i] = true
        } else {
            usbPs[i] = false
        }
    }
}

var nUsb,nPs,iU,iP int
var usbCost []int
var psCost []int

func addMouse(usb bool) {
	if usb {
		totCost += int64(usbCost[iU])
		nComp++
		iU++
	} else {
		totCost += int64(psCost[iP])
		nComp++
		iP++
	}
	//fmt.Println("added mouse usb = ", usb, " totCost: ", totCost)
}

func solve() {
	nUsb = 0; nPs = 0
	for i:=0; i<m; i++ {
		if usbPs[i] {
			nUsb++
		} else {
			nPs++
		}
	}
	//fmt.Println("nUsb,nPs = ", nUsb, nPs)
	usbCost = make([]int, nUsb)
	psCost = make([]int, nPs)
	iU = 0; iP = 0
	for i:=0; i<m; i++ {
		if usbPs[i] {
			usbCost[iU] = mCost[i]
			iU++
		} else {
			psCost[iP] = mCost[i]
			iP++
		}
	}
	// sort costs
	sort.Ints(usbCost)
	sort.Ints(psCost)
	// deal with USB only
	iU = 0; iP = 0; nComp = 0
	for ; iU<nUsb && iU<a; {
		addMouse(true)
	}
	// deal with ps2
	for ; iP<nPs && iP<b; {
		addMouse(false)
	}
	// deal with comps using USB & PS2
	ic := 0
	for (iU<nUsb || iP<nPs) && ic<c {
		if iU<nUsb && iP<nPs {
			if usbCost[iU] < psCost[iP] {
				addMouse(true)
			} else {
				addMouse(false)
			}
		} else {
			if iU<nUsb {
				addMouse(true)
			} else {
				addMouse(false)
			}
		}
		ic++
	}
}

func printRes() {
	fmt.Println(nComp," ",totCost)
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

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

func ReadInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

type mouse struct {
	price int
	mType string
}

func main() {
	defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    usb, ps2, b := ReadInt(), ReadInt(), ReadInt()

    m := ReadInt()

    var v []mouse

    for ; m > 0; m-- {
    	var mo mouse
    	mo.price = ReadInt()
    	scanner.Scan()
    	mo.mType = scanner.Text()
    	v = append(v, mo)
    }

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

   	qt := 0
   	total := 0

   	for _,elem := range v {

   		if elem.mType == "USB" {
   			if usb > 0 {
   				usb--
   				qt++
   				total += elem.price
   			} else if b > 0 {
   				b--
   				qt++
   				total += elem.price
   			}
   		} else {
   			if ps2 > 0 {
   				ps2--
   				qt++
   				total += elem.price
   			} else if b > 0 {
   				b--
   				qt++
   				total += elem.price
   			}
   		}
   	}

	writer.WriteString(strconv.Itoa(qt))
	writer.WriteString(" ")
	writer.WriteString(strconv.Itoa(total))
	writer.WriteString("\n")

}

// Codeforces 774 C done
package main

import (
"bufio"
"fmt"
"strings"
"strconv"
	"os"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var a,b,c,m int
var mCost []int
var usbPs []bool
var nComp int
var totCost int64

func readData() {
	in = bufio.NewReader(os.Stdin)
	a,b,c,_,_ = readFive()
	m,_,_,_,_ = readFive()
	usbPs = make([]bool, m)
	mCost = make([]int, m)
	for i:=0; i<m; i++ {
        s, err := in.ReadString('\n')
        if err != nil {
            fmt.Println("read mouse failure", err)
            panic(err)
        }
        ss := strings.Split(strings.Trim(s, " \n\r"), " ")
        mCost[i],_ = strconv.Atoi(ss[0])
        if ss[1][0] == 'U' {
            usbPs[i] = true
        } else {
            usbPs[i] = false
        }
    }
}

var nUsb,nPs,iU,iP int
var usbCost []int
var psCost []int

func addMouse(usb bool) {
	if usb {
		totCost += int64(usbCost[iU])
		nComp++
		iU++
	} else {
		totCost += int64(psCost[iP])
		nComp++
		iP++
	}
	//fmt.Println("added mouse usb = ", usb, " totCost: ", totCost)
}

func solve() {
	nUsb = 0; nPs = 0
	for i:=0; i<m; i++ {
		if usbPs[i] {
			nUsb++
		} else {
			nPs++
		}
	}
	//fmt.Println("nUsb,nPs = ", nUsb, nPs)
	usbCost = make([]int, nUsb)
	psCost = make([]int, nPs)
	iU = 0; iP = 0
	for i:=0; i<m; i++ {
		if usbPs[i] {
			usbCost[iU] = mCost[i]
			iU++
		} else {
			psCost[iP] = mCost[i]
			iP++
		}
	}
	// sort costs
	sort.Ints(usbCost)
	sort.Ints(psCost)
	// deal with USB only
	iU = 0; iP = 0; nComp = 0
	for ; iU<nUsb && iU<a; {
		addMouse(true)
	}
	// deal with ps2
	for ; iP<nPs && iP<b; {
		addMouse(false)
	}
	// deal with comps using USB & PS2
	for (iU<nUsb && iU<a+c) || (iP<nPs && iP<b+c) {
		if (iU<nUsb && iU<a+c) && (iP<nPs && iP<b+c) {
			if usbCost[iU] < psCost[iP] {
				addMouse(true)
			} else {
				addMouse(false)
			}
		} else {
			if (iU<nUsb && iU<a+c) {
				addMouse(true)
			} else {
				addMouse(false)
			}
		}
	}
}

func printRes() {
	fmt.Println(nComp," ",totCost)
}

func main() {
	readData()
	solve()
	printRes()
}


// Codeforces 789 B
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var b1 int64
var l int64
var q,m int
var a []int
var nItems int
var aset map[int64]bool

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	var b1i int
	var li int
	b1i,q,li,m,_ = readFive()
	b1 = int64(b1i)
	l = int64(li)
	a = readLineNumbs(m)
}

func checkAddVal(v int64) {
	_,have := aset[v]
	if !have {
		nItems += 1
	}
}

func solve() {
	aset = make(map[int64]bool)
	for i:=0; i<m; i++ {
		aset[int64(a[i])] = true
	}
	nItems = 0
	if b1==0 {
		// only element 0
		_,have := aset[0]
		if !have {
			nItems = -1
		}
		return
	} else if b1>l || -b1>l {
		return
	} else if q==0 {
		// only element 0
		_,have := aset[0]
		if !have {
			nItems = -1
		} else {
			checkAddVal(b1)
		}
		return
	} else if q==1 {
		// always b1
		_,have := aset[b1]
		if !have {
			nItems = -1
		} else {
			nItems=0
		}
		return
	} else if q==-1 {
		// b1, -b1
		_,have := aset[b1]
		if !have {
			nItems = -1
		} else {
			_,have = aset[-b1]
			if !have {
				nItems = -1
			}
		}
		return
	} else {
		// normal geom sequence, count element
		for (b1<=l) && (-b1<=l) {
			checkAddVal(b1)
			b1 = b1*int64(q)
		}
	}
}

func printRes() {
	if nItems>=0 {
		fmt.Println(nItems)
	} else {
		fmt.Println("inf")
	}
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func abs(a int64) int64 {
    if a < 0 {
        return -a
    }
    return a
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

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

func searchInt64(a []int64, v int64) bool {
    idx := sort.Search(len(a), func (i int) bool { return a[i] >= v })
    return idx < len(a) && a[idx] == v
}

type Int64s []int64

func (s Int64s) Len() int {
    return len(s)
}

func (s Int64s) Less(i, j int) bool {
    return s[i] < s[j]
}

func (s Int64s) Swap(i, j int) {
    s[i], s[j] = s[j], s[i]
}

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

    // your code here
    var b, q, l, m int64
    scanf("%d %d %d %d\n", &b, &q, &l, &m)
    am := scanints()
    sort.Sort(Int64s(am))
    counted := make(map[int64]struct{})
    skipped := make(map[int64]struct{})
    var used struct{}
    for abs(b) <= l {
        if _, ok := skipped[b]; ok {
            if q == -1 && len(counted) > 0 {
                fmt.Println("inf")
                return
            }
            break
        }
        if _, ok := counted[b]; ok {
            fmt.Println("inf")
            return
        }
        if searchInt64(am, b) {
            skipped[b] = used
        } else {
            counted[b] = used
        }
        b *= q
    }
    fmt.Println(len(counted))
}

package main

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

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(a int64) int64 {
    if a < 0 {
        return -a
    }
    return a
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

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

func searchInt64(a []int64, v int64) bool {
    idx := sort.Search(len(a), func (i int) bool { return a[i] >= v })
    return idx < len(a) && a[idx] == v
}

type Int64s []int64

func (s Int64s) Len() int {
    return len(s)
}

func (s Int64s) Less(i, j int) bool {
    return s[i] < s[j]
}

func (s Int64s) Swap(i, j int) {
    s[i], s[j] = s[j], s[i]
}

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

    // your code here
    var b1, q, l, m int64
    scanf("%d %d %d %d\n", &b1, &q, &l, &m)
    am := scanints()
    sort.Sort(Int64s(am))
    if q != 0 && int64(abs(b1)) > l {
        fmt.Println( 0)
        return
    }
    if abs(q) <= 1 || b1 == 0 {
        if searchInt64(am, b1) {
            fmt.Println(0)
            return
        }
        if q == -1 {
            if searchInt64(am, -b1) {
                fmt.Println(0)
                return
            }
        }
        fmt.Println("inf")
        return
    }
    var b int64 = int64(b1)
    count := 1
    for abs(b*q) <= l {
        b *= q
        if !searchInt64(am, b) {
            count++
        }
    }
    fmt.Println(count)
}

package main

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

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(a int64) int64 {
    if a < 0 {
        return -a
    }
    return a
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

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

func searchInt64(a []int64, v int64) bool {
    idx := sort.Search(len(a), func (i int) bool { return a[i] >= v })
    return idx < len(a) && a[idx] == v
}

type Int64s []int64

func (s Int64s) Len() int {
    return len(s)
}

func (s Int64s) Less(i, j int) bool {
    return s[i] < s[j]
}

func (s Int64s) Swap(i, j int) {
    s[i], s[j] = s[j], s[i]
}

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

    // your code here
    var b, q, l, m int64
    scanf("%d %d %d %d\n", &b, &q, &l, &m)
    am := scanints()
    sort.Sort(Int64s(am))
    counted := make(map[int64]struct{})
    skipped := make(map[int64]struct{})
    var used struct{}
    if abs(b) <= l && !searchInt64(am, b) {
        counted[b] = used
    } else {
        skipped[b] = used
    }
    for {
        b *= q
        if abs(b) > l {
            break
        }
        if _, ok := skipped[b]; ok {
            break
        }
        if _, ok := counted[b]; ok {
            fmt.Println("inf")
            return
        }
        if searchInt64(am, b) {
            skipped[b] = used
        } else {
            counted[b] = used
        }
    }
    fmt.Println(len(counted))
}

package main

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

func abs(a int64) int64 {
    if a < 0 {
        return -a
    }
    return a
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

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

func searchInt64(a []int64, v int64) bool {
    idx := sort.Search(len(a), func (i int) bool { return a[i] >= v })
    return idx < len(a) && a[idx] == v
}

type Int64s []int64

func (s Int64s) Len() int {
    return len(s)
}

func (s Int64s) Less(i, j int) bool {
    return s[i] < s[j]
}

func (s Int64s) Swap(i, j int) {
    s[i], s[j] = s[j], s[i]
}

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

    // your code here
    var b, q, l, m int64
    scanf("%d %d %d %d\n", &b, &q, &l, &m)
    am := scanints()
    sort.Sort(Int64s(am))
    counted := make(map[int64]struct{})
    skipped := make(map[int64]struct{})
    var used struct{}
    if abs(b) <= l && !searchInt64(am, b) {
        counted[b] = used
    } else {
        skipped[b] = used
    }
    for {
        b *= q
        if abs(b) > l {
            break
        }
        if _, ok := skipped[b]; ok {
            if q == -1 && len(counted) > 0 {
                fmt.Println("inf")
                return
            }
            break
        }
        if _, ok := counted[b]; ok {
            fmt.Println("inf")
            return
        }
        if searchInt64(am, b) {
            skipped[b] = used
        } else {
            counted[b] = used
        }
    }
    fmt.Println(len(counted))
}

package main

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

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(a int64) int64 {
    if a < 0 {
        return -a
    }
    return a
}

var in *bufio.Reader

func scanf(format string, a ...interface{}) (int, error) {
    return fmt.Fscanf(in, format, a...)
}

func scanln() string {
    s, _ := in.ReadString('\n')
    return strings.TrimSpace(s)
}

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

func searchInt64(a []int64, v int64) bool {
    idx := sort.Search(len(a), func (i int) bool { return a[i] >= v })
    return idx < len(a) && a[idx] == v
}

type Int64s []int64

func (s Int64s) Len() int {
    return len(s)
}

func (s Int64s) Less(i, j int) bool {
    return s[i] < s[j]
}

func (s Int64s) Swap(i, j int) {
    s[i], s[j] = s[j], s[i]
}

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

    // your code here
    var b, q, l, m int64
    scanf("%d %d %d %d\n", &b, &q, &l, &m)
    am := scanints()
    sort.Sort(Int64s(am))
    counted := make(map[int64]struct{})
    skipped := make(map[int64]struct{})
    var used struct{}
    count := 0
    if abs(b) <= l && !searchInt64(am, b) {
        count++
        counted[b] = used
    } else {
        skipped[b] = used
    }
    for {
        b *= q
        if abs(b) > l {
            break
        }
        if _, ok := skipped[b]; ok {
            break
        }
        if _, ok := counted[b]; ok {
            fmt.Println("inf")
            return
        }
        if searchInt64(am, b) {
            skipped[b] = used
        } else {
            count++
            counted[b] = used
        }
    }
    fmt.Println(count)
}

// Codeforces 789 B
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var b1,q,l,m int
var a []int
var nItems int
var aset map[int]bool

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n
	b1,q,l,m,_ = readFive()
	a = readLineNumbs(m)
}

func checkAddVal(v int) {
	_,have := aset[v]
	if !have {
		nItems += 1
	}
}

func solve() {
	aset = make(map[int]bool)
	for i:=0; i<m; i++ {
		aset[a[i]] = true
	}
	nItems = 0
	if b1==0 {
		// only element 0
		_,have := aset[0]
		if !have {
			nItems = -1
		}
		return
	} else if b1>l || -b1>l {
		return
	} else if q==0 {
		// only element 0
		_,have := aset[0]
		if !have {
			nItems = -1
		} else {
			checkAddVal(b1)
		}
		return
	} else if q==1 {
		// always b1
		_,have := aset[b1]
		if !have {
			nItems = -1
		} else {
			nItems=0
		}
		return
	} else if q==-1 {
		// b1, -b1
		_,have := aset[b1]
		if !have {
			nItems = -1
		} else {
			_,have = aset[-b1]
			if !have {
				nItems = -1
			}
		}
		return
	} else {
		// normal geom sequence, count element
		for (b1<=l) && (-b1<=l) {
			checkAddVal(b1)
			b1 = b1*q
		}
	}
}

func printRes() {
	if nItems>=0 {
		fmt.Println(nItems)
	} else {
		fmt.Println("inf")
	}
}

func main() {
	readData()
	solve()
	printRes()
}


package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		a, b := in(), in()

		if 2*a < b {
			b = 2 * a
		}

		if 2*b < a {
			a = 2 * b
		}

		n := (2*b - a) / 3
		m := (a - n) / 2

		fmt.Println(m + n)

	}
}

package main

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

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

	n := readNum(reader)

	for n > 0 {
		n--
		a, b := readTwoNums(reader)
		fmt.Println(solve(a, b))
	}
}

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, b int) int {
	return min(a, b, (a+b)/3)
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		a, b := 0, 0
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		if a < b {
			a, b = b, a
		}
		c := a - b
		//fmt.Println(a, b, c)
		ans := 0
		if c >= b {
			ans = b
		} else {
			p := (b - c) / 3
			ans = c + p*2
			b -= c
			b -= p * 3
			if b == 2 {
				ans++
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
	"math"
)

func main(){
	var i, t int64
	var a, b float64

	fmt.Scan(&t)

	for i = 0; i<t; i++{
		fmt.Scan(&a)
		fmt.Scan(&b)

		res := math.Min(a, math.Min(b, (a+b)/3))
		fr := int64(res)

		fmt.Println(fr)
	}
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(nextInt64(), nextInt64()))
	}
}

func solve(a, b int64) int64 {
	return Min((a+b)/3, a, b)
}

func Min(xs ...int64) int64 {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

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

func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt64()
	}
	return ret
}

/*
URL:
https://codeforces.com/contest/1366/problem/A
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt2()

		solve()
	}
}

func solve() {
	if a < b {
		a, b = b, a
	}

	diff := a - b
	if diff > b {
		fmt.Println(b)
		return
	}

	ans := diff
	a -= 2 * diff
	b -= diff

	c := (a + b) / 3
	ans += c
	fmt.Println(ans)
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/contest/1366/problem/A
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt2()

		solve()
	}
}

func solve() {
	ans := BinarySearch(0, INF_BIT30, func(c int) bool {
		if a-c < 0 || b-c < 0 {
			return false
		}

		return (a-c)+(b-c) >= c
	})

	fmt.Println(ans)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

var nTest, a, b int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscan(in, &a, &b)

		if a < b {
			a, b = b, a
		}

		if a >= 2*b {
			fmt.Fprintln(out, b)
			continue
		}

		t := 0
		if a != b {
			t = a - b
		}

		res := t + (a-2*t)/3*2
		if (a-2*t)%3 == 2 {
			res++
		}
		fmt.Fprintln(out, res)
	}
	out.Flush()
}

package main

import "fmt"

func Min(x, y int64) int64 {
	if x < y {
		return x
 	}
 	return y
}

func main () {
	var t, a, b, i int64
	var num1, num2 int64
	fmt.Scanf("%d\n", &t)
	for i = 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		num1 = Min(a, b)
		num2 = Min(num1, (a+b)/3)
		fmt.Println(num2)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var t, a, b int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a, &b)
		if a > b {
			a, b = b, a
		}
		c := 2*a - b
		if c < 0 {
			c = 0
		}
		ans := 0
		for x := c / 3; x <= c/3+1; x++ {
			y := min(a-2*x, (b-x)/2)
			if y >= 0 && x+y > ans {
				ans = x + y
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, a, b int
	for Scan(&t); t > 0; t-- {
		Scan(&a, &b)
		Println(min(min(a, b), (a+b)/3))
	}
}

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

package main
import "fmt"
func main(){
	var N int
	fmt.Scan(&N)
	ans := make([]int, N)
	for i:=0; i<N; i++{
		var A, B int
		fmt.Scan(&A, &B)
		ans[i] = min(A, min(B, (A+B)/3))
	}
	for _, a := range ans{
		fmt.Println(a)
	}
}
func min(a, b int) int {
	if a<b{
		return a
	}
	return b
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int64
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var p, a, ans int64
		fmt.Fscanf(in, "%v %v\n", &p, &a)
		val := (p + a) / 3
		second := 2*val - p
		first := val - second
		if first < 0 || second < 0{
			otb := int(math.Max(math.Min(float64(p/2), float64(a)), math.Min(float64(a/2), float64(p))))
			fmt.Fprintln(out, otb)
			continue
		}
		ans = first + second
		fmt.Fprintln(out, ans)
	}
	return
}

/*
2* (a - 2x) <= b-x

2a - 4x <= b - x

2a-b <= 3x
x >= (2a-b)/3
*/

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for T > 0 {
		T--
		var a,b int
		fmt.Scan(&a,&b)
		if a < b {
			a,b = b,a
		}
		if a > 2 * b {
			fmt.Println(b)
			continue
		}
		x := (2*a - b) / 3
		if x * 3 < 2*a - b {
			x ++
		}
		ans := x
		a -= 2*x
		ans += a
		fmt.Println(ans)

	}
}

// Codeforces - Shovels and Swords - 1366A
package main

import "fmt"

func Min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var t, a, b int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b)
		fmt.Println(Min(a, Min(b, (a+b)/3)))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		testcase(scanner, writer)
	}
}
func testcase(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	if a < b {
		a, b = b, a
	}
	d := min(a-b, b)
	a -= d << 1
	b -= d
	d += b / 3 * 2
	a -= b / 3 * 3
	b -= b / 3 * 3
	if b > 0 && a > 1 {
		d++
	}
	fmt.Fprintln(writer, d)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    Int64() int64
    UInt64() uint64
    String() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) UInt64() uint64 {
    impl.Scan()
    bb := impl.Bytes()
    i := uint64(0)
    for _, b := range bb {
        i *= 10
        i += uint64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) String() string {
    impl.Scan()
    return impl.Text()
}

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

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

func abs(a int64) int64 {
    if a < 0 {
        return a * -1
    }
    return a
}

func min(a int64, rest ...int64) int64 {
    for _, r := range rest {
        if r < a {
            a = r
        }
    }
    return a
}

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

const (
    INF = int64(math.MaxInt64)
    MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		a := reader.Int64()
		b := reader.Int64()
		writer.Printf("%d\n", sol(a, b))
	}
}

func sol(a, b int64) int64 {
	return min(a, b, (a+b)/3)
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

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

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

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

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

func sol(a, b int64) int64 {
	return min(a, b, (a+b)/3)
}

package main

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

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

	n := readNum(reader)

	for n > 0 {
		n--
		a, b := readTwoNums(reader)
		fmt.Println(solve(a, b))
	}
}

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, b int) int {
	if a <= b/2 {
		return a
	}

	if b <= a/2 {
		return b
	}

	x := b / 3
	y := a - 2*x

	if 2*y+x > b {
		y--
	}

	return x + y
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		a, b := 0, 0
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		if a < b {
			a, b = b, a
		}
		c := a - b
		//fmt.Println(a, b, c)
		ans := 0
		if c >= b {
			ans = b
		} else {
			ans = c + (b-c)/3*2
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		a, b := 0, 0
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		if a < b {
			a, b = b, a
		}
		c := a - b
		//fmt.Println(a, b, c)
		ans := 0
		if c >= b {
			ans = b
		} else {
			p := (b - c) / 3
			ans = c + p*2
			b -= p * 3
			if b == 2 {
				ans++
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		a, b := in(), in()

		if 2*a < b {
			b = 2 * a
		}

		if 2*b < a {
			a = 2 * b
		}

		n := (2*b - a) / 3
		m := (2*a - b) / 3

		if m < 0 || n < 0 {
			fmt.Println(0)
		} else {
			fmt.Println(m + n)
		}
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		a, b := in(), in()

		n := (2*b - a) / 3
		m := (2*a - b) / 3

		if m < 0 || n < 0 {
			fmt.Println(0)
		} else {
			fmt.Println(m + n)
		}
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		a, b := in(), in()

		if 2*a < b {
			b = 2 * a
		}

		if 2*b < a {
			a = 2 * b
		}

		n := (2*b - a) / 3
		m := (2*a - b) / 3

		fmt.Println(m + n)

	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		a, b := in(), in()

		n := (2*b - a) / 3
		m := (a - n) / 2

		if m < 0 || n < 0 {
			fmt.Println(0)
		} else {
			fmt.Println(m + n)
		}
	}
}

package main

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

var nTest, a, b int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscan(in, &a, &b)

		if a < b {
			a, b = b, a
		}

		if a >= 2*b {
			fmt.Fprintln(out, b)
			continue
		}

		t := 0
		if a != b {
			t = a - b
		}

		fmt.Fprintln(out, t+(a-2*t)/3*2)
	}
	out.Flush()
}

package main

import "fmt"

func main () {
	var t, a, b, ctr int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		if a == 0 || b == 0 {
			ctr = 0
		}
		if a == 1 && b == 1 {
			ctr = 0
		} else {
			if a >= 2*b {
				ctr = b
			}
			if b >= 2*a {
				ctr = a
			} else {
				ctr = (a+b)/3
			}
		}
		fmt.Println(ctr)
	}
}

package main

import "fmt"

func main () {
	var t, a, b, ctr int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		if a == 0 || b == 0 {
			ctr = 0
		} else {
			if a >= 2*b {
				ctr = b
			}
			if b >= 2*a {
				ctr = a
			} else {
				ctr = (a+b)/3
			}
		}
		fmt.Println(ctr)
	}
}

package main

import "fmt"

func main () {
	var t, a, b, ctr int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		if a == 0 || b == 0 {
			ctr = 0
		} else if a == 1 && b == 1 {
			ctr = 0
		} else {
			if a >= 2*b {
				ctr = b
			}
			if b >= 2*a {
				ctr = a
			} else {
				ctr = (a+b)/3
			}
		}
		fmt.Println(ctr)
	}
}

package main
import "fmt"
func main(){
	var N int
	fmt.Scan(&N)
	for i:=0; i<N; i++{
		var A, B int
		fmt.Scan(&A, &B)
		fmt.Println(A, min(B, (A+B)/3))
	}
}
func min(a, b int) int {
	if a<b{
		return a
	}
	return b
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var p, a, ans int
		fmt.Fscanf(in, "%v %v\n", &p, &a)
		val := int((p + a) / 3)
		second := 2*val - p
		first := val - second
		if first < 0 || second < 0{
			fmt.Fprintln(out, 0)
			continue
		}
		ans = first + second
		fmt.Fprintln(out, ans)
	}
	return
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var p, a, ans int
		fmt.Fscanf(in, "%v %v\n", &p, &a)
		val := (p + a) / 3
		second := 2*val - p
		first := val - second
		if first < 0 || second < 0{
			fmt.Fprintln(out, 0)
			continue
		}
		ans = first + second
		fmt.Fprintln(out, ans)
	}
	return
}

package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    Int64() int64
    UInt64() uint64
    String() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) UInt64() uint64 {
    impl.Scan()
    bb := impl.Bytes()
    i := uint64(0)
    for _, b := range bb {
        i *= 10
        i += uint64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) String() string {
    impl.Scan()
    return impl.Text()
}

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

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

func abs(a int64) int64 {
    if a < 0 {
        return a * -1
    }
    return a
}

func min(a int64, rest ...int64) int64 {
    for _, r := range rest {
        if r < a {
            a = r
        }
    }
    return a
}

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

const (
    INF = int64(math.MaxInt64)
    MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		a := reader.Int64()
		b := reader.Int64()
		writer.Printf("%d\n", sol(a, b))
	}
}

func sol(a, b int64) int64 {
	// make b larger
	if a > b {
		b, a = a, b
	}
	x := min(b-a, a)
	a -= x
	b -= x*2
	return x + min(a,b)/3*2
}