package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

func solve() {
    var n, m int
    fmt.Fscan(input, &n, &m)
    if n == 1 && m == 1 {
        fmt.Fprintln(output, 0)
        return
    }

    if n == 1 || m == 1 {
        fmt.Fprintln(output, 1)
        return
    }

    fmt.Fprintln(output, 2)
}

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 t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		if n == 1 && m == 1 {
			fmt.Fprintln(out, 0)
		} else if n == 1 || m == 1 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		r, c := 0, 0
		fmt.Fscan(f, &r, &c)
		if r == 1 && c == 1 {
			fmt.Fprintln(w, 0)
		} else if r == 1 || c == 1 {
			fmt.Fprintln(w, 1)
		} else {
			fmt.Fprintln(w, 2)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main(){
	var N_INPS, width, height int
	var inputs [][2]int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	N_INPS, _ = strconv.Atoi(scanner.Text())
	for i:=0; i<N_INPS; i++{
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &width, &height)
		inputs = append(inputs, [2]int{width, height})
	}
	for _, dims := range inputs{
		fmt.Println(min_points(dims[0], dims[1]))
	}
}

func min_points(width, height int) int{
	if width <  height{
		return min_points(height, width)
	}
	if width == height && height == 1{
		return 0
	} else if height == 1{
		return 1
	} else {
		return 2
	}
}

package main

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

func main(){
  var n_inps int
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  fmt.Sscanf(scanner.Text(), "%d", &n_inps)
  var inputs [][2]int
  var a,b int
  for i:=0; i<n_inps; i++{
    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d %d", &a, &b)
    inputs = append(inputs, [2]int{a,b})
  }
  for _, input := range inputs{
    fmt.Println(compute(input[0], input[1]))
  }
}

func compute (a, b int) int{
  if a < b{
    return compute(b,a)
  }
  if b==1{
    if a==1{
      return 0
    } else{
      return 1
    }
  } else{
    return 2
  }
}

package main

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

/*
4
2 3
3 1
3 3
4 4
---
2
1
2
2
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)

		var ans int

		switch {
		case n == 1 && m == 1:
			ans = 0
		case n == 1 || m == 1:
			ans = 1
		default:
			ans = 2
		}

		fmt.Fprintln(&bld, ans)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

func solve(n, m int) int {
	if n == 1 && m == 1 {
		return 0
	}
	if n == 1 || m == 1 {
		return 1
	}
	return 2
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)
		fmt.Println(solve(n, m))
	}
}

package main

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

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

	x := mustReadInt(r)
	for i := int64(0); i < x; i++ {
		nums := mustReadNNumbs(r, 2)
		n, m := nums[0], nums[1]

		if n == 1 && m == 1 {
			fmt.Println("0")
		} else if n == 1 || m == 1 {
			fmt.Println("1")
		} else {
			fmt.Println("2")
		}
	}

}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

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

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 solve() {
    var n, m int
    fmt.Fscan(input, &n, &m)

    if n == 1 || m == 1 {
        fmt.Fprintln(output, 1)
        return
    }

    fmt.Fprintln(output, 2)
}

package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

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

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 solve() {
    var n, m int
    fmt.Fscan(input, &n, &m)

    if n == 1 || m == 1 {
        fmt.Fprintln(output, 1)
        return
    }

    fmt.Fprintln(output, 3)
}

package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

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

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 solve() {
    var n, m int
    fmt.Fscan(input, &n, &m)

    if n == 1 || m == 1 {
        fmt.Fprintln(output, 1)
        return
    }

    if n == 2 || m == 2 {
        fmt.Fprintln(output, 2)
        return
    }

    fmt.Fprintln(output, 3)
}

package main

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

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

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

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

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 solve() {
    var n, m int
    fmt.Fscan(input, &n, &m)
    if n == 1 && m == 1 {
        fmt.Fprintln(output, 0)
        return
    }

    if n == 1 || m == 1 {
        fmt.Fprintln(output, 1)
        return
    }

    if n == 2 || m == 2 {
        fmt.Fprintln(output, 2)
        return
    }

    fmt.Fprintln(output, 3)
}

package main

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

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

	x := mustReadInt(r)
	for i := int64(0); i < x; i++ {
		nums := mustReadNNumbs(r, 2)
		n, m := nums[0], nums[1]
		if n == 1 || m == 1 {
			fmt.Print("1 ")
		} else {
			fmt.Print("2 ")
		}
	}

}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

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

	x := mustReadInt(r)
	for i := int64(0); i < x; i++ {
		nums := mustReadNNumbs(r, 2)
		n, m := nums[0], nums[1]
		if n == 1 || m == 1 {
			fmt.Println("1")
		} else {
			fmt.Println("2")
		}
	}

}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

package main

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

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

	n := mustReadInt(r)
	for i := int64(0); i < n; i++ {
		nums := mustReadNNumbs(r, 2)
		n, m := nums[0], nums[1]
		if n == 1 || m == 1 {
			fmt.Println("1")
		} else {
			fmt.Println("2")
		}
	}

}

func mustReadNNumbs(r *bufio.Reader, n int64) []int64 {
	nums := make([]int64, n)
	var err error
	for i, s := range strings.Split(mustReadLine(r), " ") {
		nums[i], err = strconv.ParseInt(s, 10, 64)
		checkError(err)
	}
	return nums
}

func mustReadInt(r *bufio.Reader) int64 {
	numb, err := strconv.ParseInt(mustReadLine(r), 10, 64)
	checkError(err)
	return numb
}

func mustReadLine(r *bufio.Reader) string {
	s, _, err := r.ReadLine()
	checkError(err)
	return string(s)
}

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

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 t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		min := n
		if m < n {
			min = m
		}

		if n == 1 && m == 1 {
			fmt.Fprintln(out, 0)
		} else if min == 1 {
			fmt.Fprintln(out, 1)
		} else if min == 2 {
			fmt.Fprintln(out, 2)
		} else {
			fmt.Fprintln(out, 3)
		}
	}
}

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 t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		min := n
		if m < n {
			min = m
		}

		if min == 1 {
			fmt.Fprintln(out, 1)
		} else if min == 2 {
			fmt.Fprintln(out, 2)
		} else {
			fmt.Fprintln(out, 3)
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		r, c := 0, 0
		fmt.Fscan(f, &r, &c)
		if r == 1 && c == 1 {
			fmt.Fprintln(w, 0)
		} else if r < c {
			fmt.Fprintln(w, r)
		} else {
			fmt.Fprintln(w, c)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		r, c := 0, 0
		fmt.Fscan(f, &r, &c)
		if r < c {
			fmt.Fprintln(w, r)
		} else {
			fmt.Fprintln(w, c)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main(){
  var n_inps int
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  fmt.Sscanf(scanner.Text(), "%d", &n_inps)
  var inputs [][2]int
  var a,b int
  for i:=0; i<n_inps; i++{
    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d %d", &a, &b)
    inputs = append(inputs, [2]int{a,b})
  }
  for _, input := range inputs{
    fmt.Println(compute(input[0], input[1]))
  }
}

func compute (a, b int) int{
  if a < b{
    return compute(b,a)
  }
  if b==1{
    return 1
  } else{
    return 2
  }
}


package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const MAX = 3000

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

func main() {
	var n, a, g, sa, sg int
	scanf("%d\n", &n)

	c := make([]byte, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &a, &g)

		if abs(sa + a - sg) < abs(sg + g - sa) {
			sa += a
			c[i] = 'A'
		} else {
			sg += g
			c[i] = 'G'
		}
	}
	if abs(sa - sg) > 500 {
		fmt.Println(-1)
	} else {
		fmt.Println(string(c))
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    cntA := 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        g, _ := strconv.Atoi(scanner.Text())
        if (cntA+a) <= 500 {
            cntA += a
            writer.WriteRune('A')
        } else {
            cntA -= g
            writer.WriteRune('G')
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var t,x,y int
	sa,sb:=0,0
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&t)
	for i:=0;i<t;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		x=aa
		input.Scan()
		bb,_:= strconv.Atoi(input.Text())
		y=bb
		if (sa+x-sb)<=500 {
			sa+=x
			out.WriteRune('A')
		} else {
			sb+=y
			out.WriteRune('G')
		}
	}
	out.Flush()
}

package main

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

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

func read_ints() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i, v := range words {
		a[i], _ = strconv.Atoi(v)
	}
	return a
}

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

func main() {
	n := read_ints()[0]
	x := make([][]int, n+2)
	for i := 1; i <= n; i++ {
		x[i] = read_ints()
	}
	sa := make([]int, n+2)
	sb := make([]int, n+2)
	for i := 1; i <= n; i++ {
		sa[i] = sa[i-1] + x[i][0]
	}
	for i := n; i > 0; i-- {
		sb[i] = sb[i+1] + x[i][1]
	}
	for i := 0; i <= n; i++ {
		if abs(sa[i]-sb[i+1]) <= 500 {
			j := 1
			for ; j <= i; j++ {
				out.WriteByte('A')
			}
			for ; j <= n; j++ {
				out.WriteByte('G')
			}
			out.WriteByte('\n')
			out.Flush()
			break
		}
	}
}

package main

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

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

func read_ints() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i, v := range words {
		a[i], _ = strconv.Atoi(v)
	}
	return a
}

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

func main() {
	n := read_ints()[0]
	sum := 0
	for i := 1; i <= n; i++ {
		sum += read_ints()[0]
	}
	k := (sum + 499) / 1000
	for i := 0; i < k; i++ {
		out.WriteByte('G')
	}
	for i := k; i < n; i++ {
		out.WriteByte('A')
	}
	out.Flush()
}

//  URL: http://codeforces.com/contest/282/problem/B
//  ~ Basic Greedy/Implementation Problem

package main

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

func solve(n int, prices [][2]int) []string {
	delta := 0
	ans := make([]string, n)
	for i := 0; i < n; i++ {
		if delta + prices[i][0] <= 500 {
			ans[i] = "A"
			delta += prices[i][0]
		} else {
			ans[i] = "G"
			delta -= prices[i][1]
		}
	}
	return ans
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	prices := make([][2]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &prices[i][0], &prices[i][1])
	}
	fmt.Fprintln(writer, strings.Join(solve(n, prices), ""))
}

// 282B-mic
package main

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

func main() {
    d := bufio.NewScanner(os.Stdin)
    d.Split(bufio.ScanWords)
    w := bufio.NewWriter(os.Stdout)
    var n, a, g int
    fmt.Scan(&n)
    s := make([]rune, n)
    for i := 0; i < n; i++ {
        d.Scan()
        x, _ := strconv.Atoi(d.Text())
        d.Scan()
        y, _ := strconv.Atoi(d.Text())
        //fmt.Scan(&x, &y)
        if a+x-g <= 500 {
            a += x
            s[i] = 'A'
            w.WriteString(string(s[i]))
        } else {
            g += y
            s[i] = 'G'
            w.WriteString(string(s[i]))
        }
    }
    w.Flush()
    fmt.Println()
}

package main

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

var in = bufio.NewReader(os.Stdin)

func read_ints() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i, v := range words {
		a[i], _ = strconv.Atoi(v)
	}
	return a
}

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

func main() {
	n := read_ints()[0]
	x := make([][]int, n+2)
	for i := 1; i <= n; i++ {
		x[i] = read_ints()
	}
	sa := make([]int, n+2)
	sb := make([]int, n+2)
	for i := 1; i <= n; i++ {
		sa[i] = sa[i-1] + x[i][0]
	}
	for i := n; i > 0; i-- {
		sb[i] = sb[i+1] + x[i][1]
	}
	for i := 1; i <= n; i++ {
		if abs(sa[i]-sb[i+1]) <= 500 {
			j := 1
			for ; j <= i; j++ {
				fmt.Printf("A")
			}
			for ; j <= n; j++ {
				fmt.Printf("G")
			}
			fmt.Println()
			break
		}
	}
}


package main

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

var n int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	var a, b int64
	for i := 0; i < n; i++ {
		var x int64
		fmt.Fscanf(reader, "%d", &x)
		if i&1 == 0 {
			a += x / 2
			b += (x + 1) / 2
		} else {
			a += (x + 1) / 2
			b += x / 2
		}
	}
	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}

package main

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

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

func slove(n int, an []int64) int64 {
	var b_cnt, w_cnt int64
	b_cnt, w_cnt = 0, 0
	for i := 0; i < n; i++ {
		if (i & 1) == 1 {
			b_cnt += (an[i] + 1) / 2
			w_cnt += an[i] / 2
		} else {
			w_cnt += (an[i] + 1) / 2
			b_cnt += an[i] / 2
		}
	}

	return min(w_cnt, b_cnt)
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int64
var b, w int64

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	b, w = 0, 0
	for i := 0; i < n; i++ {
		l := A[i]
		if i%2 == 0 {
			// Bから塗り始める
			b += (l + (2 - 1)) / 2
			w += l / 2
		} else {
			// Wから塗り始める
			w += (l + (2 - 1)) / 2
			b += l / 2
		}
	}

	fmt.Println(Min(b, w))
}

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

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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

package main

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

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

func get_num(pre, cur, remain int64) int64 {
	return (cur-pre-remain)/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][3]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(0, an[i], 0), dp[i][1]+get_num(1, an[i], 0))
		dp[i+1][1] = max(dp[i][0]+get_num(0, an[i], 1), dp[i][2]+get_num(1, an[i]-1, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(0, an[i]-1, 1), dp[i][2]+get_num(1, an[i], 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}

		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()
	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][4]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		if an[i] >= 2 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		}
		if an[i] >= 3 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][3]+get_num(an[i]-3, 1))
		}

		dp[i+1][1] = dp[i][0] + get_num(an[i]-1, 1)
		if an[i] >= 2 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][2]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][3]+get_num(an[i]-3, 1))
		}

		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][2] = max(dp[i+1][2], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 3 {
			dp[i+1][3] = max(dp[i][0]+get_num(an[i]-3, 2), dp[i][1]+get_num(an[i]-3, 1))
			dp[i+1][3] = max(dp[i+1][3], dp[i][2]+get_num(an[i]-3, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func max3(a, b, c int) int {
	return max(max(a, b), max(b, c))
}

func get_num(pre, cur, remain int) int {
	return (cur-pre-remain)/2 + remain
}

func slove(n int, an []int) int {
	dp := make([][3]int, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(0, an[i], 0), dp[i][1]+get_num(1, an[i], 0))
		dp[i+1][1] = max(dp[i][0]+get_num(0, an[i], 1), dp[i][2]+get_num(1, an[i]-1, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(0, an[i]-1, 1), dp[i][2]+get_num(1, an[i], 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}

		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()
	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][3]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		dp[i+1][1] = max(dp[i][0]+get_num(an[i]-1, 1), dp[i][2]+get_num(an[i]-2, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][3]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		dp[i+1][1] = max(dp[i][0]+get_num(an[i]-1, 1), dp[i][2]+get_num(an[i]-2, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(pre, cur, remain int64) int64 {
	return (cur-pre-remain)/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][3]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(0, an[i], 0), dp[i][1]+get_num(1, an[i], 0))
		dp[i+1][1] = max(dp[i][0]+get_num(0, an[i], 1), dp[i][2]+get_num(1, an[i]-1, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(0, an[i]-1, 1), dp[i][1]+get_num(1, an[i], 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][4]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		if an[i] >= 2 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		}
		if an[i] >= 3 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][3]+get_num(an[i]-3, 1))
		}

		dp[i+1][1] = dp[i][0] + get_num(an[i]-1, 1)
		if an[i] >= 2 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][2]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][3]+get_num(an[i]-3, 1))
		}

		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][2] = max(dp[i+1][2], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 3 {
			dp[i+1][3] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
			dp[i+1][3] = max(dp[i+1][3], dp[i][2]+get_num(an[i]-3, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][4]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		if an[i] >= 2 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		}
		if an[i] >= 3 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][3]+get_num(an[i]-3, 1))
		}
		dp[i+1][1] = max(dp[i][0]+get_num(an[i]-1, 1), dp[i][2]+get_num(an[i]-2, 1))
		if an[i] >= 3 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][2] = max(dp[i+1][2], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 3 {
			dp[i+1][3] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
			dp[i+1][3] = max(dp[i+1][3], dp[i][2]+get_num(an[i]-3, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][3]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		if an[i] >= 2 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		}
		dp[i+1][1] = max(dp[i][0]+get_num(an[i]-1, 1), dp[i][2]+get_num(an[i]-2, 1))
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

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

func get_num(cur, remain int64) int64 {
	return cur/2 + remain
}

func slove(n int, an []int64) int64 {
	dp := make([][4]int64, n+1)

	for i := 0; i < n; i++ {
		dp[i+1][0] = max(dp[i][0]+get_num(an[i], 0), dp[i][1]+get_num(an[i]-1, 0))
		if an[i] >= 2 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][2]+get_num(an[i]-2, 0))
		}
		if an[i] >= 3 {
			dp[i+1][0] = max(dp[i+1][0], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 2 {
			dp[i+1][1] = max(dp[i][0]+get_num(an[i]-1, 1), dp[i][2]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 2 {
			dp[i+1][2] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
		}
		if an[i] >= 3 {
			dp[i+1][2] = max(dp[i+1][2], dp[i][3]+get_num(an[i]-3, 1))
		}
		if an[i] >= 3 {
			dp[i+1][3] = max(dp[i][0]+get_num(an[i]-2, 1), dp[i][1]+get_num(an[i]-2, 1))
			dp[i+1][3] = max(dp[i+1][3], dp[i][2]+get_num(an[i]-3, 1))
		}
		//fmt.Printf("dp[%d] = %d\n", i+1, dp[i+1])
	}

	return dp[n][0]
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	for {
		var n int
		_, err := fmt.Fscanln(in, &n)
		if err != nil {
			break
		}

		an := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &an[i])
		}
		res := slove(n, an)

		fmt.Fprintln(out, res)

		out.Flush()

		_, err = fmt.Fscanln(in, &n)

	}
}

package main

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

var n int
var a []int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	b := make([]int, n)
	copy(b, a)
	dir := 1
	ans := 0
	for i := 0; i < n; i++ {
		if i == n-1 || a[i]%2 == 0 {
			ans += a[i] / 2
			continue
		}
		if dir == 1 {
			ans += a[i]/2 + 1
			dir = -dir
			a[i+1]--
		} else {
			if b[i] == b[i+1] {
				ans += a[i]/2 + 1
				dir = -dir
				a[i+1]--
			} else {
				ans += a[i] / 2
				dir = -dir
			}
		}
	}

	fmt.Println(ans)
}

package main

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

var n int
var a []int64

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	b := make([]int64, n)
	copy(b, a)
	dir := 1
	var ans int64
	for i := 0; i < n; i++ {
		if i == n-1 || a[i]%2 == 0 {
			ans += a[i] / 2
			continue
		}
		if dir == 1 {
			ans += a[i]/2 + 1
			dir = -dir
			a[i+1]--
		} else {
			if b[i] == b[i+1] {
				ans += a[i]/2 + 1
				dir = -dir
				a[i+1]--
			} else {
				ans += a[i] / 2
				dir = -dir
			}
		}
	}

	fmt.Println(ans)
}

package main

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

var n int
var a []int

func main() {
	stdin := os.Stdin
	stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	b := make([]int, n)
	copy(b, a)
	dir := 1
	ans := 0
	for i := 0; i < n; i++ {
		if i == n-1 || a[i]%2 == 0 {
			ans += a[i] / 2
			continue
		}
		if dir == 1 {
			ans += a[i]/2 + 1
			dir = -dir
			a[i+1]--
		} else {
			if b[i] == b[i+1] {
				ans += a[i]/2 + 1
				dir = -dir
				a[i+1]--
			} else {
				ans += a[i] / 2
				dir = -dir
			}
		}
	}

	fmt.Println(ans)
}

package main

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

var n int
var a []int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	dir := 1
	ans := 0
	for i := 0; i < n; i++ {
		if i == n-1 || a[i]%2 == 0 {
			ans += a[i] / 2
			continue
		}
		if dir == 1 {
			ans += a[i]/2 + 1
			dir = -dir
			a[i+1]--
		} else {
			if a[i] == a[i+1] {
				ans += a[i]/2 + 1
				dir = -dir
				a[i+1]--
			} else {
				ans += a[i] / 2
				dir = -dir
			}
		}
	}

	fmt.Println(ans)
}

package main

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

var n int
var a []int64

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	b := make([]int64, n)
	copy(b, a)
	dir := 1
	var ans int64
	for i := 0; i < n; i++ {
		if i == n-1 || a[i]%2 == 0 {
			ans += a[i] / 2
			dir = 1
			continue
		}
		if dir == 1 {
			ans += a[i]/2 + 1
			dir = -dir
			a[i+1]--
		} else {
			if b[i] == b[i+1] {
				ans += a[i]/2 + 1
				dir = -dir
				a[i+1]--
			} else {
				ans += a[i] / 2
				dir = -dir
			}
		}
	}

	fmt.Println(ans)
}

package main

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

var n int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	var a, b int
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscanf(reader, "%d", &x)
		if i&1 == 0 {
			a += x / 2
			b += (x + 1) / 2
		} else {
			a += (x + 1) / 2
			b += x / 2
		}
	}
	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int64
var A []int64
var ans int64
var parities []int

func main() {
	n = ReadInt64()
	A = ReadInt64Slice(int(n))

	for i := int64(0); i < n; i++ {
		ans += A[i] / 2
	}

	parities = make([]int, int(n))
	for i := int64(0); i < n; i++ {
		parities[i] = int(A[i]) % 2
	}

	press, counts := RunLengthEncoding(parities)
	for i := 0; i < len(press); i++ {
		if press[i] == 0 {
			continue
		}
		ans += int64(counts[i]) / 2
	}

	fmt.Println(ans)
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
	- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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


package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int64(1e15)
		minIndex := 0

		arr := make([]int64, n)
		for i := 0; i < n-1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			if arr[i] < minValue {
				minValue = arr[i]
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n-1])
		if arr[n-1] < minValue {
			minValue = arr[n - 1]
			minIndex = n - 1
		}

		if n == 1 {
			fmt.Fprintln(out, 0)
			continue
		}

		if minIndex == 0 {
			fmt.Fprintln(out, n-1)
		} else {
			fmt.Fprintln(out, n)
			fmt.Fprintln(out, 1, minIndex+1, minValue, arr[0])
		}

		arr[0], arr[minIndex] = minValue, arr[0]
		now := arr[0] + 1

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, 1, i+1, arr[0], now)
			now++
		}
	}
}

package main

//Attention!!!
//Fscan(in,&xx),Fprintln(out,&xx)
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
var a[100010] int

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	Fscan(in,&t)
	for T:=1;T<=t;T++{
		var n int
		x:=1000000007
		y:=1000021003
		Fscan(in,&n)
		for i:=1;i<=n;i++{
			Fscan(in,&a[i])
		}
		Fprintln(out,n-1)
		for i:=1;i<n;i++ {
			if i&1==1{

				Fprintln(out,i,i+1,x,min(a[i],a[i+1]))

				a[i+1]=min(a[i],a[i+1])
				a[i]=x
			}else{
				Fprintln(out,i,i+1,y,min(a[i],a[i+1]))

				a[i+1]=min(a[i],a[i+1])
				a[i]=y
			}

		}

	}
}
func main() { solve(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		o := 1000000007
		fmt.Fprintln(out, (n)/2)
		for i := 0; i+1 < n; i += 2 {
			fmt.Fprintln(out, i+1, i+2, min(a[i], a[i+1]), o)
		}
		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

/*
1
5
2 1 3 3 1
P 1 P P 1
========
1
4
2 4 1 1
---
2 P 1 P

========
9 6 3 11 15
6 P 3 P  11

6 1000000007 3 1000000007 11
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	fmt.Fprintln(writer, n/2)

	for i := 1; i < n; i += 2 {
		const prime = 1000000007
		fmt.Fprintln(writer, i, i+1, min(a[i-1], a[i]), prime)
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return nums[minNumIdx]
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return nums[maxNumIdx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
func abs(x int) int {
    if x < 0 {
        return -x
    } else {
        return x
    }
}
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        mn, pos := int(1E9) + 7, -1
        for i := range a {
            if a[i] < mn {
                mn = a[i]
                pos = i
            }
        }
        fmt.Println(n - 1)
        for i := range a {
            if pos == i {
                continue
            }
            fmt.Println(pos + 1, i + 1, mn, mn + abs(pos - i))
        }
    }
}

package main

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

func min(a, b int) int {

	if a < b {
		return a
	}
	return b
}

func run(r io.Reader, w io.Writer) {

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	solve := func() {

		var n int

		fmt.Fscan(in, &n)

		a := make([]int, n)

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

			fmt.Fscan(in, &a[i])

		}

		o := 1000000007

		fmt.Fprintln(out, (n / 2))

		for i := 1; i < n; i += 2 {

			fmt.Fprintln(out, i, i+1, min(a[i-1], a[i]), o)
		}
		fmt.Fprintln(out)

	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

func main() {

	run(os.Stdin, os.Stdout)
}

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) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := [][4]int{}
		for i := 1; i < n; i++ {
			v, w := a[i-1], a[i]
			if v < w {
				for gcd(v, w) > 1 {
					w++
				}
				a[i] = w
				ans = append(ans, [4]int{i - 1, i, v, w})
			} else {
				for gcd(v, w) > 1 || i > 1 && gcd(a[i-2], v) > 1 {
					v++
				}
				a[i-1] = v
				ans = append(ans, [4]int{i - 1, i, v, w})
			}
		}
		Fprintln(out, len(ans))
		for _, a := range ans {
			Fprintln(out, a[0]+1, a[1]+1, a[2], a[3])
		}
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

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

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

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var q int
	_, err := fmt.Fscan(in, &q)
	if err != nil {
		return
	}
	for i := 0; i<q; i++ {
		var n int
		_, err := fmt.Fscan(in,&n)
		if err != nil {
			return
		}
		var a = make([]int, n)
		for j:=0; j<n; j++{
			_, err = fmt.Fscan(in, &a[j])
			if err != nil {
				return
			}
		}
		var y = 1000000007
		fmt.Println(n/2)
		for j:=0; j<n-1;j+=2{
			fmt.Println(j+1," ",j+2, " ", min(a[j], a[j+1])," ", y)
		}
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		aa := make([]int, n)
		g, gIdx := math.MaxInt32, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] < g {
				g = aa[i]
				gIdx = i
			}
		}

		fmt.Fprintln(out, n-1)
		for i := 0; i < n; i++ {
			if i == gIdx {
				continue
			}
			fmt.Fprintln(out, gIdx+1, i+1, g, abs(i-gIdx)+g)
		}
	}
}

package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int64(1e15)
		minIndex := 0

		arr := make([]int64, n)
		for i := 0; i < n-1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			if arr[i] < minValue {
				minValue = arr[i]
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n-1])
		if arr[n-1] < minValue {
			minValue = arr[n - 1]
			minIndex = n - 1
		}

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		if minIndex == 0 {
			fmt.Fprintln(out, n-1)
		} else {
			fmt.Fprintln(out, n)
			fmt.Fprintln(out, 1, minIndex+1, minValue, arr[0])
		}

		arr[0], arr[minIndex] = minValue, arr[0]
		now := arr[0] + 1

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, 1, i+1, arr[0], now)
			now++
		}
	}
}

package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int64(1e15)
		minIndex := 0

		arr := make([]int64, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			minValue = min(minValue, arr[i])
			if minValue == arr[i] {
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		if minIndex == 0 {
			fmt.Fprintln(out, n)
			fmt.Fprintln(out, 1, minIndex + 1, minValue, arr[0])
		} else {
			fmt.Fprintln(out, n - 1)
		}

		arr[0], arr[minIndex] = minValue, arr[0]
		now := arr[0] + 1

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, 1, i + 1, arr[0], now)
			now++
		}
	}
}

package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int64(1e15)
		minIndex := 0

		arr := make([]int64, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			minValue = min(minValue, arr[i])
			if minValue == arr[i] {
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n)

		fmt.Fprintln(out, 1, minIndex + 1, minValue, arr[0])

		arr[0], arr[minIndex] = minValue, arr[0]
		now := arr[0] + 1

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, 1, i + 1, arr[0], now)
			now++
		}
	}
}

package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int64(1e15)
		minIndex := 0

		arr := make([]int64, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			minValue = min(minValue, arr[i])
			if minValue == arr[i] {
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n)

		fmt.Fprintln(out, 1, minIndex + 1, minValue, arr[0])

		arr[0], arr[minIndex] = minValue, arr[0]
		now := arr[0] + 1

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, i, i + 1, arr[0], now)
			now++
		}
	}
}

package main

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

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		minValue := int(1e9 + 1)
		minIndex := 0

		arr := make([]int, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			minValue = min(minValue, arr[i])
			if minValue == arr[i] {
				minIndex = i
			}
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n)

		fmt.Fprintln(out, 1, minIndex + 1, minValue, arr[0])

		arr[0], arr[minIndex] = minValue, arr[0]

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, i, i + 1, arr[i - 1], arr[i - 1] + 1)
			arr[i] = arr[i - 1] + 1
		}
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		arr := make([]int, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n / 2)

		for i := 1; i < n; i+=2 {
			minValue := int(math.Min(float64(arr[i - 1]), float64(arr[i])))
			fmt.Fprintln(out, i, i + 1, minValue, 1)
		}
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		arr := make([]int, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n)

		minValue := int(math.Min(float64(arr[0]), float64(arr[1])))
		fmt.Fprintln(out, 1, 2, 100, minValue)
		arr[0] = 100
		arr[1] = minValue

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, i, i + 1, arr[i - 1], arr[i - 1] + 1)
			arr[i] = arr[i - 1] + 1
		}
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for k := 0; k < t; k++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		arr := make([]int, n)
		for i := 0; i < n - 1; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "%d\n", &arr[n - 1])

		if n == 1 {
			fmt.Println(out, 0)
			continue
		}

		fmt.Fprintln(out, n)

		minValue := int(math.Min(float64(arr[0]), float64(arr[1])))
		fmt.Fprintln(out, 1, 2, 100, minValue)
		arr[1] = minValue

		for i := 1; i < n; i++ {
			fmt.Fprintln(out, i, i + 1, arr[i - 1], arr[i - 1] + 1)
			arr[i] = arr[i - 1] + 1
		}
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		aa := make([]int, n)
		g, gIdx := math.MaxInt32, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] < g {
				g = aa[i]
				gIdx = i
			}
		}

		fmt.Fprintln(out, n-1)
		for i := 0; i < n; i++ {
			if i == gIdx {
				continue
			}

			if i < gIdx {
				fmt.Fprintln(out, gIdx+1, i+1, gIdx-i+g, g)
			} else {
				fmt.Fprintln(out, gIdx+1, i+1, g, i-gIdx+g)
			}
		}
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		aa := make([]int, n)
		g, gIdx := math.MaxInt32, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
			if aa[i] < g {
				g = aa[i]
				gIdx = i
			}
		}

		fmt.Fprintln(out, n-1)
		for i := 0; i < n; i++ {
			if i == gIdx {
				continue
			}
			fmt.Fprintln(out, gIdx+1, i+1, abs(i-gIdx)+g, g)
		}
	}
}

package main

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

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

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

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

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

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

		bb := [][]int{}
		for i := 1; i < n; i++ {
			if gcd(aa[i-1], aa[i]) > 1 {
				d := min(aa[i-1], aa[i])
				bb = append(bb, []int{i, i + 1, d, d + 1})
				aa[i] = d + 1
			}
		}
		fmt.Fprintln(out, len(bb))
		for _, e := range bb {
			fmt.Fprintf(out, "%d %d %d %d\n", e[0], e[1], e[2], e[3])
		}
	}
}

package main

//Attention!!!
//Fscan(in,&xx),Fprintln(out,&xx)
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
var a[100010] int

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	Fscan(in,&t)
	for T:=1;T<=t;T++{
		var n int
		x:=1000000007
		y:=1000021003
		Fscan(in,&n)
		for i:=1;i<=n;i++{
			Fscan(in,&a[i])
		}
		Fprintln(out,n-1)
		for i:=1;i<n;i++ {
			if i&1==1{

				Fprintln(out,i,i+1,x,min(a[i],a[i+1]))
				a[i]=x
				a[i+1]=min(a[i],a[i+1])
			}else{
				Fprintln(out,i,i+1,y,min(a[i],a[i+1]))
				a[i]=y
				a[i+1]=min(a[i],a[i+1])
			}

		}

	}
}
func main() { solve(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

//Attention!!!
//Fscan(in,&xx),Fprintln(out,&xx)
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
var a[100010] int

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	Fscan(in,&t)
	for T:=1;T<=t;T++{
		var n int
		x:=1000000007
		y:=1000021003
		Fscan(in,&n)
		for i:=1;i<=n;i++{
			Fscan(in,&a[i])
		}
		Fprintln(out,n-1)
		for i:=1;i<n;i++ {
			if i&1==1{
				Fprintln(out,x,min(a[i],a[i+1]))
				a[i]=x
				a[i+1]=min(a[i],a[i+1])
			}else{
				Fprintln(out,y,min(a[i],a[i+1]))
				a[i]=y
				a[i+1]=min(a[i],a[i+1])
			}

		}

	}
}
func main() { solve(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		o := 1000000007
		fmt.Fprintln(out, (n)/2)
		for i := 0; i+1 < n; i += 2 {
			fmt.Fprintln(out, i+1, i+2, a[i], o)
		}
		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

/*
1
5
2 1 3 3 1
P 1 P P 1

========
9 6 3 11 15
6 P 3 P  11

6 1000000007 3 1000000007 11
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	fmt.Fprintln(writer, n-1)

	for i := 1; i < n; i += 2 {
		const prime = 1000000007
		fmt.Fprintln(writer, i, i+1, min(a[i-1], a[i]), prime)
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return nums[minNumIdx]
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return nums[maxNumIdx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}


package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	x, y, z := nextInt()%4, nextInt()%2, nextInt()%4
	p := nextInt()
	xk, yk := 0, 0
	N, M := n, m

	for i:=0; i<p; i++ {
		xk, yk = nextInt(), nextInt()
		n, m = N, M

		for j:=0; j<x; j++ {
			xk, yk = yk, n+1-xk
			m, n = n, m
		}

		for j:=0; j<y; j++ {
			yk = m + 1 - yk
		}

		// for j:=0; j<z; j++ {
		// 	yk, xk = xk, m+1-yk
		// 	m, n = n, m
		// }

		for j:=0; j<z; j++ {
			for t:=0; t<3; t++ {
				xk, yk = yk, n+1-xk
				m, n = n, m
			}
		}

		fmt.Fprintln(writer, xk, yk)
	}
}

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

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

// 400C
package main

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

func main() {
	var i, n, m, x, y, z, p, a, b, temp, tem int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n, &m, &x, &y, &z, &p)
	x %= 4
	y %= 2
	z %= 4
	for i = 0; i < p; i++ {
		tx, ty, tz, tn, tm := x, y, z, n, m
		fmt.Fscan(in, &a, &b)
		for ; tx > 0; tx-- {
			temp = a
			a = b
			b = tn + 1 - temp
			tem = tn
			tn = tm
			tm = tem
		}
		if ty != 0 {
			b = tm + 1 - b
		}
		tz = 4 - tz
		for ; tz > 0; tz-- {
			temp = a
			a = b
			b = tn + 1 - temp
			tem = tn
			tn = tm
			tm = tem
		}
		fmt.Fprintln(out, a, b)
	}
	out.Flush()
}

package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	x, y, z := nextInt()%4, nextInt()%2, nextInt()%4
	p := nextInt()
	xk, yk := 0, 0
	N, M := n, m

	for i:=0; i<p; i++ {
		xk, yk = nextInt(), nextInt()
		n, m = N, M

		for j:=0; j<x; j++ {
			xk, yk = yk, n+1-xk
			m, n = n, m
		}

		for j:=0; j<y; j++ {
			yk = m + 1 - yk
		}

		for j:=0; j<z; j++ {
			yk, xk = xk, m+1-yk
			m, n = n, m
		}

		// for j:=0; j<z; j++ {
		// 	for t:=0; t<3; t++ {
		// 		xk, yk = yk, n+1-xk
		// 		m, n = n, m
		// 	}
		// }

		fmt.Fprintln(writer, xk, yk)
	}
}

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

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

/*********************************************************************************
*     File Name           :     C.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-06 00:14]
*     Last Modified       :     [2014-03-06 19:28]
*     Description         :
**********************************************************************************/

package main

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

var n, m, x, y, z, p int

func op1(a, b int) (int, int) {
    a, b = b, n-a+1
    n, m = m, n
    return a, b
}

func op2(a, b int) (int, int) {
    a, b = a, m+1-b
    return a, b
}

func op3(a, b int) (int, int) {
    a, b = m-b+1, a
    n, m = m, n
    return a, b
}

func main() {
    scanner.Split(bufio.ScanWords)

    n = scanner.nextInt()
    m = scanner.nextInt()
    x = scanner.nextInt() % 4
    y = scanner.nextInt() % 2
    z = scanner.nextInt() % 4
    p = scanner.nextInt()
    N, M := n, m
    for i := 0; i < p; i++ {
        var a, b int
        n, m = N, M
        a = scanner.nextInt()
        b = scanner.nextInt()
        for i := 0; i < x; i++ {
            a, b = op1(a, b)
        }
        for i := 0; i < y; i++ {
            a, b = op2(a, b)
        }
        for i := 0; i < z; i++ {
            a, b = op3(a, b)
        }
        fmt.Printf("%d %d\n", a, b)
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

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

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, m, x, y, z int64
	var p int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	m, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	x, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	y, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	z, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	p, _ = strconv.Atoi(r.Text())
	var xx, yy int
	nn := n
	mm := m
	x = x%4
	y = y%2
	z = z%4
	for i:=0; i<p; i++ {
		r.Scan()
		xx, _ = strconv.Atoi(r.Text())
		r.Scan()
		yy, _ = strconv.Atoi(r.Text())
		n = nn
		m = mm
		for j:=0; int64(j)<x; j++ {
			xx, yy = yy, int(n-int64(xx)+1)
			n, m = m, n
		}
		for j:=0; int64(j)<y; j++ {
			yy = int(m-int64(yy)+1)
		}
		for j:=0; int64(j)<z; j++ {
			xx, yy = int(m-int64(yy)+1), xx
			n, m = m, n
		}
		w.WriteString(strconv.Itoa(xx)+" "+strconv.Itoa(yy)+"\n")
	}
	w.Flush()

}

package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()
	x, y, z := nextInt()%4, nextInt()%2, nextInt()%4
	p := nextInt()
	xk, yk := 0, 0

	for i:=0; i<p; i++ {
		xk,yk = nextInt(), nextInt()

		for j:=0; j<x; j++ {
			xk, yk = yk, max(m, n)+1-xk
		}

		for j:=0; j<y; j++ {
			yk = m + 1 - yk
		}

		for j:=0; j<z; j++ {
			yk, xk = xk, max(m, n)+1-yk
		}

		fmt.Fprintln(writer, xk, yk)
	}
}

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

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()
	x, y, z := nextInt()%4, nextInt()%2, nextInt()%4
	p := nextInt()
	xk, yk := 0, 0

	for i:=0; i<p; i++ {
		xk,yk = nextInt(), nextInt()

		for j:=0; j<x; j++ {
			xk, yk = yk, n+1-xk
		}

		for j:=0; j<y; j++ {
			yk = m + 1 - yk
		}

		for j:=0; j<z; j++ {
			yk, xk = xk, m+1-yk
		}

		fmt.Fprintln(writer, xk, yk)
	}
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

package main

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

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

//Wrong
func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()
	x, y, z := nextInt()%4, nextInt()%2, nextInt()%4
	p := nextInt()
	xk, yk := 0, 0

	for i:=0; i<p; i++ {
		xk,yk = nextInt(), nextInt()

		for j:=0; j<x; j++ {
			xk, yk = yk, max(m, n)+1-xk
			m, n = n, m
		}

		for j:=0; j<y; j++ {
			yk = m + 1 - yk
		}

		for j:=0; j<z; j++ {
			yk, xk = xk, max(m, n)+1-yk
			m, n = n, m
		}

		// for j:=0; j<z; j++ {
		// 	for t:=0; t<3; t++ {
		// 		xk, yk = yk, max(m, n)+1-xk
		// 	}
		// }

		fmt.Fprintln(writer, xk, yk)
	}
}

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

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

/*********************************************************************************
*     File Name           :     C.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-06 00:14]
*     Last Modified       :     [2014-03-06 00:22]
*     Description         :
**********************************************************************************/

package main

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

var n, m, x, y, z, p int

func op1(a, b int) (int, int) {
    a, b = b, n-a+1
    return a, b
}

func op2(a, b int) (int, int) {
    a, b = a, m+1-b
    return a, b
}

func op3(a, b int) (int, int) {
    a, b = m-b+1, a
    return a, b
}

func main() {
    scanner.Split(bufio.ScanWords)

    n = scanner.nextInt()
    m = scanner.nextInt()
    x = scanner.nextInt() % 4
    y = scanner.nextInt() % 2
    z = scanner.nextInt() % 4
    p = scanner.nextInt()
    for i := 0; i < p; i++ {
        var a, b int
        a = scanner.nextInt()
        b = scanner.nextInt()
        for i := 0; i < x; i++ {
            a, b = op1(a, b)
        }
        for i := 0; i < y; i++ {
            a, b = op2(a, b)
        }
        for i := 0; i < z; i++ {
            a, b = op3(a, b)
        }
        fmt.Printf("%d %d\n", a, b)
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

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

/*********************************************************************************
*     File Name           :     C.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-06 00:14]
*     Last Modified       :     [2014-03-06 19:24]
*     Description         :
**********************************************************************************/

package main

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

var n, m, x, y, z, p int

func op1(a, b int) (int, int) {
    a, b = b, n-a+1
    n, m = m, n
    return a, b
}

func op2(a, b int) (int, int) {
    a, b = a, m+1-b
    return a, b
}

func op3(a, b int) (int, int) {
    a, b = m-b+1, a
    n, m = m, n
    return a, b
}

func main() {
    scanner.Split(bufio.ScanWords)

    n = scanner.nextInt()
    m = scanner.nextInt()
    x = scanner.nextInt() % 4
    y = scanner.nextInt() % 2
    z = scanner.nextInt() % 4
    p = scanner.nextInt()
    for i := 0; i < p; i++ {
        var a, b int
        a = scanner.nextInt()
        b = scanner.nextInt()
        for i := 0; i < x; i++ {
            a, b = op1(a, b)
        }
        for i := 0; i < y; i++ {
            a, b = op2(a, b)
        }
        for i := 0; i < z; i++ {
            a, b = op3(a, b)
        }
        fmt.Printf("%d %d\n", a, b)
    }
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

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

// 400C
package main

import (
	"fmt"
)

func swap(j, k int) {
	var tem int
	tem = j
	j = k
	k = tem
}
func main() {
	var i, n, m, x, y, z, p, a, b, temp int
	fmt.Scan(&n, &m, &x, &y, &z, &p)
	x %= 4
	y %= 2
	z %= 4
	for i = 0; i < p; i++ {
		tx, ty, tz, tn, tm := x, y, z, n, m
		fmt.Scan(&a, &b)
		for ; tx > 0; tx-- {
			temp = a
			a = b
			b = tn + 1 - temp
			swap(tn, tm)
		}
		if ty != 0 {
			b = tm + 1 - b
		}
		tz = 4 - tz
		for ; tz > 0; tz-- {
			temp = a
			a = b
			b = tn + 1 - temp
			swap(tn, tm)
		}
		fmt.Println(a, b)
	}
}


package main

import (
  "os"
  "bufio"
  "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 Driver struct {
  Name string
  Points int
  Places map[int]int
  MaxPlace int
}

var drivers = map[string]*Driver{}

type OldList []*Driver
type NewList []*Driver
func (list OldList) Len() int {
  return len(list)
}
func (list OldList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}
func (list NewList) Len() int {
  return len(list)
}
func (list NewList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}

func (list OldList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func (list NewList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Places[1] != b.Places[1] {
    return a.Places[1] > b.Places[1]
  }
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func comparePlaces(a, b *Driver) bool {
  for p := 1; p <= a.MaxPlace || p <= b.MaxPlace; p++ {
    placesA := a.Places[p]
    placesB := b.Places[p]
    if placesA != placesB {
      return placesA > placesB
    }
  }
  return true
}

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

  points := map[int]int{ 1: 25, 2: 18, 3: 15, 4: 12, 5: 10,
      6: 8, 7: 6, 8: 4, 9: 2, 10: 1 }

  t := getI()
  for ti := 0; ti < t; ti++ {
    n := getI()
    for ni := 0; ni < n; ni++ {
      name := getS()
      place := ni+1
      driver, found := drivers[name]
      if !found {
        driver = &Driver{ name, 0, map[int]int{}, 0 }
        drivers[name] = driver
      }
      driver.Points += points[place]
      driver.Places[place] += 1
      if place > driver.MaxPlace {
        driver.MaxPlace = place
      }
    }
  }
  oldList, newList := []*Driver{}, []*Driver{}
  for _, driver := range drivers {
    oldList = append(oldList, driver)
    newList = append(newList, driver)
  }
  sort.Sort(OldList(oldList))
  sort.Sort(NewList(newList))
  writer.WriteString(fmt.Sprintf("%s\n", oldList[0].Name))
  writer.WriteString(fmt.Sprintf("%s\n", newList[0].Name))
}

package main

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

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	si, sj := fi.GetScore(), fj.GetScore()
	return fi.Rank[0] > fj.Rank[0] ||
			(fi.Rank[0] == fj.Rank[0] && si > sj) ||
			(fi.Rank[0] == fj.Rank[0] && si == sj && rank == 1)
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[j] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

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

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	return rank == 1 || (rank == 0 && fi.GetScore() > fj.GetScore())
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[j] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

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

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	return rank == 1 || (rank == 0 && fi.GetScore() > fj.GetScore())
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[i] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

import (
  "os"
  "bufio"
  "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 Driver struct {
  Name string
  Points int
  Places map[int]int
}

var drivers = map[string]*Driver{}

type OldList []*Driver
type NewList []*Driver
func (list OldList) Len() int {
  return len(list)
}
func (list OldList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}
func (list NewList) Len() int {
  return len(list)
}
func (list NewList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}

func (list OldList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func (list NewList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Places[1] != b.Places[1] {
    return a.Places[1] > b.Places[1]
  }
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func comparePlaces(a, b *Driver) bool {
  for p := 1; ; p++ {
    placesA, foundA := a.Places[p]
    placesB, foundB := b.Places[p]
    if !foundA && !foundB && p > 10 {
      break
    }
    if placesA != placesB {
      return placesA > placesB
    }
  }
  return true
}

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

  points := map[int]int{ 1: 25, 2: 18, 3: 15, 4: 12, 5: 10,
      6: 8, 7: 6, 8: 4, 9: 2, 10: 1 }

  t := getI()
  for ti := 0; ti < t; ti++ {
    n := getI()
    for ni := 0; ni < n; ni++ {
      name := getS()
      place := ni+1
      driver, found := drivers[name]
      if !found {
        driver = &Driver{ name, 0, map[int]int{} }
        drivers[name] = driver
      }
      driver.Points += points[place]
      driver.Places[place] += 1
    }
  }
  oldList, newList := []*Driver{}, []*Driver{}
  for _, driver := range drivers {
    oldList = append(oldList, driver)
    newList = append(newList, driver)
  }
  sort.Sort(OldList(oldList))
  sort.Sort(NewList(newList))
  writer.WriteString(fmt.Sprintf("%s\n", oldList[0].Name))
  writer.WriteString(fmt.Sprintf("%s\n", newList[0].Name))
}