You are playing a game on a $$$n \times m$$$ grid, in which the computer has selected some cell $$$(x, y)$$$ of the grid, and you have to determine which one. To do so, you will choose some $$$k$$$ and some $$$k$$$ cells $$$(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$$$, and give them to the computer. In response, you will get $$$k$$$ numbers $$$b_1,\, b_2, \ldots b_k$$$, where $$$b_i$$$ is the manhattan distance from $$$(x_i, y_i)$$$ to the hidden cell $$$(x, y)$$$ (so you know which distance corresponds to which of $$$k$$$ input cells). After receiving these $$$b_1,\, b_2, \ldots, b_k$$$, you have to be able to determine the hidden cell. What is the smallest $$$k$$$ for which is it possible to always guess the hidden cell correctly, no matter what cell computer chooses?As a reminder, the manhattan distance between cells $$$(a_1, b_1)$$$ and $$$(a_2, b_2)$$$ is equal to $$$|a_1-a_2|+|b_1-b_2|$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows.  The single line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the number of rows and the number of columns in the grid.

For each test case print a single integer — the minimum $$$k$$$ for that test case.

NoteIn the first test case, the smallest such $$$k$$$ is $$$2$$$, for which you can choose, for example, cells $$$(1, 1)$$$ and $$$(2, 1)$$$.Note that you can't choose cells $$$(1, 1)$$$ and $$$(2, 3)$$$ for $$$k = 2$$$, as both cells $$$(1, 2)$$$ and $$$(2, 1)$$$ would give $$$b_1 = 1, b_2 = 2$$$, so we wouldn't be able to determine which cell is hidden if computer selects one of those.In the second test case, you should choose $$$k = 1$$$, for it you can choose cell $$$(3, 1)$$$ or $$$(1, 1)$$$.

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


The Bitlandians are quite weird people. They have very peculiar customs.As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.

The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.

If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as Sa, and the money Uncle J. must pay G. for the painting as Sg, then this inequality must hold: |Sa  -  Sg|  ≤  500.  If there are several solutions, you are allowed to print any of them.

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

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

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


You are given a Young diagram. Given diagram is a histogram with $$$n$$$ columns of lengths $$$a_1, a_2, \ldots, a_n$$$ ($$$a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$$$).    Young diagram for $$$a=[3,2,2,2,1]$$$. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a $$$1 \times 2$$$ or $$$2 \times 1$$$ rectangle.

The first line of input contain one integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$): the number of columns in the given histogram. The next line of input contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 300\,000, a_i \geq a_{i+1}$$$): the lengths of columns.

Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.

NoteSome of the possible solutions for the example:

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"
	"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"
	"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
*/

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


Nastia has received an array of $$$n$$$ positive integers as a gift.She calls such an array $$$a$$$ good that for all $$$i$$$ ($$$2 \le i \le n$$$) takes place $$$gcd(a_{i - 1}, a_{i}) = 1$$$, where $$$gcd(u, v)$$$ denotes the greatest common divisor (GCD) of integers $$$u$$$ and $$$v$$$.You can perform the operation: select two different indices $$$i, j$$$ ($$$1 \le i, j \le n$$$, $$$i \neq j$$$) and two integers $$$x, y$$$ ($$$1 \le x, y \le 2 \cdot 10^9$$$) so that $$$\min{(a_i, a_j)} = \min{(x, y)}$$$. Then change $$$a_i$$$ to $$$x$$$ and $$$a_j$$$ to $$$y$$$.The girl asks you to make the array good using at most $$$n$$$ operations.It can be proven that this is always possible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_{n}$$$ ($$$1 \le a_i \le 10^9$$$) — the array which Nastia has received as a gift. It's guaranteed that the sum of $$$n$$$ in one test doesn't exceed $$$2 \cdot 10^5$$$.

For each of $$$t$$$ test cases print a single integer $$$k$$$ ($$$0 \le k \le n$$$) — the number of operations. You don't need to minimize this number. In each of the next $$$k$$$ lines print $$$4$$$ integers $$$i$$$, $$$j$$$, $$$x$$$, $$$y$$$ ($$$1 \le i \neq j \le n$$$, $$$1 \le x, y \le 2 \cdot 10^9$$$) so that $$$\min{(a_i, a_j)} = \min{(x, y)}$$$ — in this manner you replace $$$a_i$$$ with $$$x$$$ and $$$a_j$$$ with $$$y$$$. If there are multiple answers, print any.

NoteConsider the first test case.Initially $$$a = [9, 6, 3, 11, 15]$$$.In the first operation replace $$$a_1$$$ with $$$11$$$ and $$$a_5$$$ with $$$9$$$. It's valid, because $$$\min{(a_1, a_5)} = \min{(11, 9)} = 9$$$.After this $$$a = [11, 6, 3, 11, 9]$$$.In the second operation replace $$$a_2$$$ with $$$7$$$ and $$$a_5$$$ with $$$6$$$. It's valid, because $$$\min{(a_2, a_5)} = \min{(7, 6)} = 6$$$.After this $$$a = [11, 7, 3, 11, 6]$$$ — a good array.In the second test case, the initial array is already good.

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

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

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


Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.  Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

For each of the p candies, print on a single line its space-separated new coordinates.

NoteJust for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:QWER      REWQ ASDF  ->  FDSAZXCV      VCXZ

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

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
}

// 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

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