package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var subjects [3][]int

	v := 0
	for i := 1; i <= n; i++ {
		fmt.Scan(&v)
		subjects[v-1] = append(subjects[v-1], i)
	}

	min := len(subjects[0])
	if min > len(subjects[1]) {
		min = len(subjects[1])
	}

	if min > len(subjects[2]) {
		min = len(subjects[2])
	}

	fmt.Println(min)
	for i := 0; i < min; i++ {
		fmt.Printf("%d %d %d\n", subjects[0][i], subjects[1][i], subjects[2][i])
	}
}

package main

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

const MAXN = int(5e3 + 10)

var A,B,C [MAXN] int

func min(a, b int) int{

    var ret int
    if a < b {
        ret = a
    }else {

        ret = b
    }
    return ret

}

func main(){

    reader := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(reader,&n)
    var a,b,c int
    for i := 1 ;i <= n; i ++ {
        var x int
        fmt.Fscan(reader,&x)
        if 1 == x {
            a ++
            A[a] = i

        }else if(2 == x){

            b ++
            B[b] = i
        }else {
            c ++
            C[c] = i
        }

    }
    ans := min(a,min(b,c))
    fmt.Println(ans)
    for i:=1;i <= ans; i ++ {

        fmt.Printf("%d %d %d\n",A[i],B[i],C[i])
    }

}

package main

import (
	"fmt"
)

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

func main () {
	var N int
	fmt.Scanf("%d\n", &N)

	students := make([]int, 0)
	for i := 0; i < N; i++ {
		var C int
		fmt.Scanf("%d", &C)
		students = append(students, C)
	}

	m := map[int][]int{1: []int{}, 2: []int{}, 3: []int{}}

	for index, student := range students {
		m[student] = append(m[student], index+1)
	}
	teams := 1000000
	for _, v := range m {
		teams = min(teams, len(v))
	}
	fmt.Printf("%d\n", teams)
	if teams == 0 {
		return
	}

	for i := 0; i < teams; i++ {
			fmt.Printf("%d %d %d\n", m[1][i], m[2][i], m[3][i])
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	t := make([][]int, 3)
	for i := 0; i < 3; i++ {
		t[i] = make([]int, 0, 5000)
	}
	for i := 1; i <= n; i++ {
		var x int
		fmt.Scan(&x)
		x--
		t[x] = append(t[x], i)
	}
	z := 1 << 30
	for i := 0; i < 3; i++ {
		z = min(z, len(t[i]))
	}
	fmt.Println(z)
	for i := 0; i < z; i++ {
		fmt.Printf("%d %d %d\n", t[0][0], t[1][0], t[2][0])
		for j := 0; j < 3; j++ {
			t[j] = t[j][1:]
		}
	}
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)
	var ts [5000]int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		ts[i] = t - 1
	}
	var fs [3]int
	for i := 0; i < n; i++ {
		fs[ts[i]]++
	}
	w := min(fs[0], min(fs[1], fs[2]))
	fmt.Println(w)
	printTeam := func() {
		findFirst := func(x int) int {
			for i := 0; i < n; i++ {
				t := ts[i]
				if x == t {
					ts[i] = -1
					return i + 1
				}
			}
			panic("do not reach here")
		}
		fmt.Printf("%d %d %d\n", findFirst(0), findFirst(1), findFirst(2))
	}
	for i := 0; i < w; i++ {
		printTeam()
	}
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

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

var n int

func main() {
	fmt.Fscan(reader, &n)
	var m [4][]int
	for i := 1; i <= n; i++ {
		var a int
		fmt.Fscan(reader, &a)
		m[a] = append(m[a], i)
	}
	ans := n
	ans = Min(ans, len(m[1]))
	ans = Min(ans, len(m[2]))
	ans = Min(ans, len(m[3]))
	fmt.Println(ans)
	for i := 0; i < ans; i++ {
		fmt.Println(m[1][i], m[2][i], m[3][i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
type Team struct {
	id uint32
	loc []uint32
}

func main() {
	var n, c1,c2,c3,c uint32
	var t uint32
	m := make(map[uint32]Team)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i:= uint32(0); i < n; i++{
		fmt.Fscanf(in, "%d", &t)
		var team Team
		team = m[t]
		team.id++
		if t == 1{
			c1++
		}else if t == 2{
			c2++
		}else if t ==3{
			c3++
		}
		team.loc = append(team.loc, i)
		m[t] = team
	}
	if c1 != 0 && c2 != 0 && c3 != 0{
		if c2 >= c1 && c3 >= c1 {
			c = c1
		}else if c2 >= c3 && c2 >= c3{
			c = c3
		}else if c1 >= c2 && c3 >= c2{
			c = c2
		}
		fmt.Println(c)
		for i:=uint32(0); i < c; i++{
			if c1 == 0 || c2 == 0 || c3 == 0{
				break
				fmt.Println()
			}
			for _, v := range m {
				fmt.Print(v.loc[0] + 1," ")
				RemoveIndex(v.loc, 0)
			}
			c1--
			c2--
			c3--
			fmt.Println()
		}
	}else{
		fmt.Println(0)
	}
}
func RemoveIndex(s []uint32, index uint32) []uint32 {
    return append(s[:index], s[index+1:]...)
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	t := make([]int, n)
	for i := range t {
		t[i] = readi() - 1
	}
	m := make([][]int, 3)
	for i, v := range t {
		m[v] = append(m[v], i+1)
	}
	l := n + 1
	for i := range m {
		l = min(l, len(m[i]))
	}
	for i := range m {
		m[i] = m[i][:l]
	}
	println(len(m[0]))
	for i := range m[0] {
		println(m[0][i], m[1][i], m[2][i])
	}
}

package main

import "fmt"

var (
	nChild int
	d int
	size int
	a,b,c bool
)

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

func main(){
	teams  := make(map[int][]int)
	fmt.Scanf("%d\n", &nChild)
	for i:=1; i<=nChild; i++{
		fmt.Scan(&d)
		teams[d] = append(teams[d], i)
	}
	programming, _ := teams[1]
	maths, _ := teams[2]
	sports, _ := teams[3]
	lessPossibleTeams := min(len(programming), len(maths))
	lessPossibleTeams = min(lessPossibleTeams, len(sports))
	fmt.Println(lessPossibleTeams)
	for x := 0; x<lessPossibleTeams; x++{
		fmt.Printf("%d %d %d\n", programming[x], maths[x], sports[x] )
	}
}

package main

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

func main() {
	var n, maxTeams, countProgs, countMaths, countPES int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	arrayOfChilds := make([]int, n)
	var arrayOfProg, arrayOfMath, arrayOfPE []int
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &arrayOfChilds[index])
	}
	for index := 0; index < n; index++ {
		if arrayOfChilds[index] == 1 {
			arrayOfProg = append(arrayOfProg, index+1)
		} else if arrayOfChilds[index] == 2 {
			arrayOfMath = append(arrayOfMath, index+1)
		} else {
			arrayOfPE = append(arrayOfPE, index+1)
		}
	}
	maxTeams = 0
	countProgs = len(arrayOfProg)
	countMaths = len(arrayOfMath)
	countPES = len(arrayOfPE)

	if countProgs < countMaths {
		maxTeams = countProgs
		if countProgs > countPES {
			maxTeams = countPES
		}
	} else {
		maxTeams = countMaths
		if countMaths > countPES {
			maxTeams = countPES
		}
	}

	fmt.Println(maxTeams)
	for index := 0; index < maxTeams; index++ {
		fmt.Print(arrayOfProg[index], " ", arrayOfMath[index], " ", arrayOfPE[index])
		fmt.Println()
	}
}

package main

import "fmt"

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

func main()  {
  var N int

  fmt.Scanf("%d\n", &N)
  T := make(map[int][]int)

  for i := 1; i <= N; i++ {
    var t int
    fmt.Scanf("%d", &t)
    T[t] = append(T[t], i)
  }

  var t1, t2, t3 int = 0, 0, 0

  maxTeams := min(len(T[1]), min(len(T[2]), len(T[3])))
  fmt.Println(maxTeams)

  for i := 0; i < maxTeams; i++ {
    fmt.Println(T[1][t1], T[2][t2], T[3][t3])
    t1++
    t2++
    t3++
  }
}

package main

import "fmt"

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

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

func main() {
	var a []int
	var b []int
	var c []int
	var n, x int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		switch x {
		case 1:
			a = append(a, i+1)
		case 2:
			b = append(b, i+1)
		case 3:
			c = append(c, i+1)
		}
	}
	ans := min(len(a), min(len(b), len(c)))
	fmt.Println(ans)
	for i := 0; i < ans; i++ {
		fmt.Println(a[i], b[i], c[i])
	}
}

package main

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

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

// https://codeforces.com/problemset/problem/490/A
// комментарии к решению
// Входной поток состоит только из цифр 1, 2 и 3, поэтому можно
// считать его как []byte и разобрать посимвольно.
// Т.к. для ответа требуется указывать порядковые номера, то
// распределяем учеников по группам с соответствующими способностями
func taskSolution(in []byte, n int) (ans string) {
	type s []int
	children := map[byte]s{
		'1': s{},
		'2': s{},
		'3': s{},
	}
	// no overflow потому что мы знаем объем входных данных
	for i, pos := 1, 0; i <= n; i, pos = i+1, pos+1 {
		// find next
		for in[pos] < '1' || in[pos] > '3' {
			pos += 1
		}
		children[in[pos]] = append(children[in[pos]], i)
	}
	// calculate
	count := min(len(children['1']), len(children['2']))
	count = min(count, len(children['3']))
	ans = fmt.Sprint(count)
	for i := 0; i < count; i += 1 {
		ans = fmt.Sprintf("%s\n%d %d %d", ans, children['1'][i], children['2'][i], children['3'][i])
	}
	return ans
}

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

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw, n))
}

package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  var programming []int
  var math []int
  var PE []int

  var skill int

  for i:=1; i <= n; i++ {
    fmt.Scan(&skill)
    if skill == 1 {
      programming = append(programming, i)
    }
    if skill == 2 {
      math = append(math, i)
    }
    if skill == 3 {
      PE = append(PE, i)
    }
  }
  noOfTeams := 0

  if len(programming) <= len(math) && len(programming) <= len(PE) {
    noOfTeams = len(programming)
  }

  if len(math) <= len(programming) && len(math) <= len(PE) {
    noOfTeams = len(math)
  }

  if len(PE) <= len(programming) && len(PE) <= len(math) {
    noOfTeams = len(PE)
  }
  fmt.Println(noOfTeams)
  for i := 0; i<noOfTeams; i++ {
    fmt.Println(fmt.Sprint(programming[i],math[i],PE[i]))
  }
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"container/list"
)

var in *bufio.Scanner = bufio.NewScanner(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

type Tuple struct{ x, y, z interface{} }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	n := nextInt()
	var a []*list.List = []*list.List{list.New(), list.New(), list.New()}
	for i := 0; i < n; i++ {
		a[nextInt() - 1].PushFront(i + 1)
	}

	var m []Tuple
	for i, j, k := a[0].Front(), a[1].Front(), a[2].Front(); i != nil && j != nil && k != nil; {
		m = append(m, Tuple{i.Value, j.Value, k.Value})
		i = i.Next()
		j = j.Next()
		k = k.Next()
	}

	fmt.Println(len(m))
	for _, i := range m {
		fmt.Printf("%d %d %d\n", i.x, i.y, i.z)
	}
}

func nextInt() int {
	in.Scan()
	res, _ := strconv.Atoi(in.Text())
	return res
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)
	var t [3][]int
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		t[v-1] = append(t[v-1], i+1)
	}
	w := min(len(t[0]), min(len(t[1]), len(t[2])))
	fmt.Println(w)
	for i := 0; i < w; i++ {
		fmt.Println(t[0][i], t[1][i], t[2][i])
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	data := make([][]int, 3)
	for i := 0; i < 3; i++ {
		data[i] = make([]int, 0)
	}
	for i := 1; i <= n; i++ {
		var x int
		fmt.Scan(&x)
		x--
		data[x] = append(data[x], i)
	}
	res := make([][]int, 0)
	for allNotEmpty(data) {
		newTeam := make([]int, 3)
		for i := 0; i < 3; i++ {
			newTeam[i] = data[i][0]
			data[i] = data[i][1:]
		}
		res = append(res, newTeam)
	}
	fmt.Printf("%v\n", len(res))
	for _, team := range res {
		fmt.Printf("%v %v %v\n", team[0], team[1], team[2])
	}
}

func allNotEmpty(a [][]int) bool {
	for _, b := range a {
		if len(b) == 0 {
			return false
		}
	}
	return true
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	part := make([][]int, 3)
	for i := 0; i < 3; i++ {
		part[i] = []int{}
	}
	for i := 1; i <= n; i++ {
		x := scanInt(scanner)-1
		part[x] = append(part[x], i)
	}
	count := len(part[0])
	if count > len(part[1]) {
		count = len(part[1])
	}
	if count > len(part[2]) {
		count = len(part[2])
	}
	writer.WriteString(fmt.Sprintf("%d\n", count))
	for i := 0; i < count; i++ {
		writer.WriteString(fmt.Sprintf("%d %d %d\n",
				part[0][i], part[1][i], part[2][i]))
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var n, t int
	fmt.Scanf("%d \n", &n)
	myMap := make(map[int][]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &t)
		myMap[t] = append(myMap[t], i+1)
	}
	count := min(len(myMap[1]), min(len(myMap[2]), len(myMap[3])))
	fmt.Println(count)
	for i := 0; i < count; i++ {
		fmt.Println(myMap[1][i], myMap[2][i], myMap[3][i])
	}
}

package main

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

var (
	n      int
	skill  [][]int
	result int
)

func in() {
	skill = make([][]int, 3)
	read(&n)
	var s int
	for i := 0; i < n; i++ {
		read(&s)
		skill[s-1] = append(skill[s-1], i+1)
	}
}

func out() {
	defer output.Flush()
}

func run() {
	w := len(skill[0])
	if len(skill[1]) < w {
		w = len(skill[1])
	}
	if len(skill[2]) < w {
		w = len(skill[2])
	}
	println(w)
	for i := 0; i < w; i++ {
		println(skill[0][i], skill[1][i], skill[2][i])
	}
}

/** main **/
func main() {
	in()
	run()
	out()
}

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

func println(a ...interface{}) {
	fmt.Fprintln(output, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(output, format, a...)
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)
	// students := make(map[int]int)
	studentsSkill1 := []int{}
	studentsSkill2 := []int{}
	studentsSkill3 := []int{}
	var ns1, ns2, ns3 int
	for i := 0; i < n; i++ {
		var skill int
		fmt.Scan(&skill)
		if skill == 1 {
			studentsSkill1 = append(studentsSkill1, i+1)
			ns1++
		} else if skill == 2 {
			studentsSkill2 = append(studentsSkill2, i+1)
			ns2++
		} else if skill == 3 {
			studentsSkill3 = append(studentsSkill3, i+1)
			ns3++
		}
	}
	// fmt.Println(studentsSkill1)
	// fmt.Println(studentsSkill2)
	// fmt.Println(studentsSkill3)
	minTeams := min(min(ns1, ns2), ns3)
	fmt.Println(minTeams)
	for i := 0; i < minTeams; i++ {
		fmt.Print(studentsSkill1[i])
		fmt.Print(" ")
		fmt.Print(studentsSkill2[i])
		fmt.Print(" ")
		fmt.Println(studentsSkill3[i])
	}

}

package main

import (
	"fmt"
	"math"
)

func main()  {
	var w int
	fmt.Scan(&w)
	t := make([]int,w)
	readN(t,0,w)
	m := map[int][]int{
		1 : make([]int, 0,w),
		2 : make([]int, 0,w),
		3 : make([]int, 0,w),
	}
	for i,v := range t {
		m[v] = append(m[v], i+1)
	}
	i := math.Min(float64(len(m[1])),math.Min(float64(len(m[2])),float64(len(m[3]))))
	fmt.Println(i)
	for j:=0;j<int(i);j++{
		fmt.Printf("%d %d %d\n",m[1][j],m[2][j],m[3][j])
	}
}

func readN(all []int, i, n int) {
    if n == 0 {
        return
    }
    if m, err := scan(&all[i]); m != 1 {
        panic(err)
    }
    readN(all, i+1, n-1)
}

func scan(a *int) (int, error) {
    return fmt.Scan(a)
}

package main
import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	var w int
	var counter1, counter2, counter3 int = 0,0,0
	var arr1,arr2, arr3 []int
	for i := 0; i < n; i++ {
		fmt.Scan(&w)
		if w == 1{
			arr1 = append(arr1,i+1)
			counter1++
		}else if w == 2{
			arr2 = append(arr2,i+1)
			counter2++
		}else{
			arr3 = append(arr3,i+1)
			counter3++
		}
	}
	minn := min(min(counter1,counter2),counter3)
	fmt.Println(minn)
	for i := 0; i < minn; i++{
		output := fmt.Sprintf("%d %d %d", arr1[i], arr2[i], arr3[i])
		fmt.Println(output)
	}

}

package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)

	var t int
	var fields [3][]int

	for i := 0; i < 3; i++ {
		fields[i] = make([]int, 0)
	}

	for i := 1; i <= n; i++ {
		fmt.Scan(&t)
		t--
		fields[t] = append(fields[t], i)
	}

	min := len(fields[0])
	for i := 1; i < 3; i++ {
		if len(fields[i]) < min {
			min = len(fields[i])
		}
	}

	fmt.Println(min)

	for i := 0; i < min; i++ {
		fmt.Println(fields[0][i], fields[1][i], fields[2][i])
	}
}

package main

import "fmt"

func main() {
	var i, tmp, ll int
	var s1, s2, s3 []int
	fmt.Scanf("%d\n", &i)

	for j:=0;j<i;j++  {
		fmt.Scanf("%d", &tmp)
		if tmp == 1 {
			s1 = append(s1, j+1)
		} else if tmp == 2 {
			s2 = append(s2, j+1)
		} else {
			s3 = append(s3, j+1)
		}
	}
	ll = min(s1,s2,s3)
	fmt.Println(ll)
	for k := 0; k < ll;k++  {
		fmt.Print(s1[k], s2[k], s3[k], "\n")
	}

}

func min(s1, s2, s3 []int) int {
	if len(s1) < len(s2) {
		if len(s1) < len(s3) {
			return len(s1)
		}
		return len(s3)
	} else {
		if len(s2) < len(s3) {
			return len(s2)
		}
		return len(s3)
	}
}

package main

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

func main() {
	var n, t int
	fmt.Scanf("%d \n", &n)
	count := 0
	reader := bufio.NewReader(os.Stdin)
	ss, _ := reader.ReadString('\n')
	list := strings.Split(strings.TrimRight(ss, "\r\n"), " ")
	arr := [][]int{[]int{}, []int{}, []int{}}
	for i := 0; i < n; i++ {
		temp, _ := strconv.ParseInt(list[i], 10, 64)
		t = int(temp) - 1
		arr[t] = append(arr[t], i+1)
		if len(arr[0]) > count && len(arr[1]) > count && len(arr[2]) > count {
			fmt.Println(arr[0][count], arr[1][count], arr[2][count])
			count++
		}
	}
	if count == 0 {
		fmt.Print(count)
	}
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	n = max(strings.Count(line, "1"), max(strings.Count(line, "2"), strings.Count(line, "3")))
	fmt.Print(n)
}

package main
import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	var w int
	var counter1, counter2, counter3 int = 0,0,0
	var arr1,arr2, arr3 []int
	for i := 0; i < n; i++ {
		fmt.Scan(&w)
		if w == 1{
			arr1 = append(arr1,i)
			counter1++
		}else if w == 2{
			arr2 = append(arr2,i)
			counter2++
		}else{
			arr3 = append(arr3,i)
			counter3++
		}
	}
	minn := min(min(counter1,counter2),counter3)
	fmt.Println(minn)
	for i := 0; i < minn; i++{
		output := fmt.Sprintf("%d %d %d", arr1[i], arr2[i], arr3[i])
		fmt.Println(output)
	}

}

package main

import "fmt"

func main() {
	var i, j, k, tmp, ll int
	var s1, s2, s3 []int
	fmt.Scanf("%d", &i)

	for j=0;j<i;j++  {
		fmt.Scanf("%d", &tmp)
		if tmp == 1 {
			s1 = append(s1, j+1)
		} else if tmp == 2 {
			s2 = append(s2, j+1)
		} else {
			s3 = append(s3, j+1)
		}
	}
	ll = min(s1,s2,s3)
	fmt.Println(ll)
	for k = 0; k < ll;k++  {
		fmt.Print(s1[k], s2[k], s3[k], "\n")
	}

}

func min(s1, s2, s3 []int) int {
	if len(s1) < len(s2) {
		if len(s1) < len(s3) {
			return len(s1)
		}
		return len(s3)
	} else {
		if len(s2) < len(s3) {
			return len(s2)
		}
		return len(s3)
	}
}

package main

import "fmt"

func main() {
	var i, j, k, tmp int
	var s1, s2, s3 []int
	fmt.Scanf("%d", &i)

	for j=0;j<i;j++  {
		fmt.Scanf("%d", &tmp)
		if tmp == 1 {
			s1 = append(s1, j+1)
		} else if tmp == 2 {
			s2 = append(s2, j+1)
		} else {
			s3 = append(s3, j+1)
		}
	}
	ll := min(s1,s2,s3)
	fmt.Println(ll)
	for k = 0; k < ll;k++  {
		fmt.Println(s1[k], s2[k], s3[k])
	}

}

func min(s1, s2, s3 []int) int {
	if len(s1) < len(s2) {
		if len(s1) < len(s3) {
			return len(s1)
		}
		return len(s3)
	} else {
		if len(s2) < len(s3) {
			return len(s2)
		}
		return len(s3)
	}
}

package main

import "fmt"

func main() {
	var i, j, k, tmp int
	var s1, s2, s3 []int
	fmt.Scanf("%d", &i)

	for j=0;j<i;j++  {
		fmt.Scanf("%d", &tmp)
		if tmp == 1 {
			s1 = append(s1, j+1)
		} else if tmp == 2 {
			s2 = append(s2, j+1)
		} else {
			s3 = append(s3, j+1)
		}
	}
	ll := min(s1,s2,s3)
	fmt.Println(ll)
	for k = 0; k < ll;k++  {
		fmt.Print(s1[k], s2[k], s3[k], "\n")
	}

}

func min(s1, s2, s3 []int) int {
	if len(s1) < len(s2) {
		if len(s1) < len(s3) {
			return len(s1)
		}
		return len(s3)
	} else {
		if len(s2) < len(s3) {
			return len(s2)
		}
		return len(s3)
	}
}

package main

import "fmt"

func main() {
    fmt.Println("Hello, 世界")
}

package main

import (
	"fmt"
)

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

func main () {
	var N int
	fmt.Scanf("%d", &N)

	students := make([]int, 0)
	for i := 0; i < N; i++ {
		var C int
		fmt.Scanf("%d", &C)
		students = append(students, C)
	}

	m := map[int]int{1: 0, 2: 0, 3: 0}

	for _, i := range students {
		m[i] += 1
	}
	limit := 100000
	for _, v := range m {
		limit = min(limit, v)
	}

	num_teams := limit
	fmt.Printf("%d\n", num_teams)
	if num_teams == 0 {
		return
	}
	for i := 0; i < N; i++ {
		if num_teams == 0 {
			break
		}

		if students[i] < 0 {
			continue
		}
		temp := map[int]bool{1: false, 2: false, 3: false}
		temp[students[i]] = true
		team := make([]int, 0)
		team = append(team, i)
		students[i] *= -1
		for j := i + 1; j < N; j++ {
					if len(team) == 3 {
						break
					}
					if students[j] < 0 {
						continue
					}

					if !temp[students[j]] {
						team = append(team, j)
						temp[students[j]] = true
						students[j] *= -1
					}
		}
		num_teams -= 1
		fmt.Printf("%d %d %d\n", team[0], team[1], team[2])
	}
}

package main

import (
	"fmt"
)

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

func main () {
	var N int
	fmt.Scanf("%d", &N)

	students := make([]int, 0)
	for i := 0; i < N; i++ {
		var C int
		fmt.Scanf("%d", &C)
		students = append(students, C)
	}

	m := map[int][]int{1: []int{}, 2: []int{}, 3: []int{}}

	for index, student := range students {
		m[student] = append(m[student], index)
	}
	teams := 1000000
	for _, v := range m {
		teams = min(teams, len(v))
	}
	fmt.Printf("%d\n", teams)
	if teams == 0 {
		return
	}

	for i := 0; i < teams; i++ {
			fmt.Printf("%d %d %d\n", m[1][i], m[2][i], m[3][i])
	}
}

package main

import (
	"fmt"
)

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

func main () {
	var N int
	fmt.Scanf("%d", &N)

	students := make([]int, 0)
	for i := 0; i < N; i++ {
		var C int
		fmt.Scanf("%d", &C)
		students = append(students, C)
	}

	m := map[int]int{1: 0, 2: 0, 3: 0}

	for _, i := range students {
		m[i] += 1
	}
	limit := 100000
	for _, v := range m {
		limit = min(limit, v)
	}

	num_teams := limit
	fmt.Printf("%d\n", num_teams)
	if num_teams == 0 {
		return
	}
	for i := 0; i < N; i++ {
		if num_teams == 0 {
			break
		}

		if students[i] < 0 {
			continue
		}
		temp := map[int]bool{1: false, 2: false, 3: false}
		temp[students[i]] = true
		team := make([]int, 0)
		team = append(team, i+1)
		students[i] *= -1
		for j := i + 1; j < N; j++ {
					if len(team) == 3 {
						break
					}
					if students[j] < 0 {
						continue
					}

					if !temp[students[j]] {
						team = append(team, j+1)
						temp[students[j]] = true
						students[j] *= -1
					}
		}
		num_teams -= 1
		fmt.Printf("%d %d %d\n", team[0], team[1], team[2])
	}
}

package main

import (
	"fmt"
)

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

func main () {
	var N int
	fmt.Scanf("%d\n", &N)

	students := make([]int, 0)
	for i := 0; i < N; i++ {
		var C int
		fmt.Scanf("%d", &C)
		students = append(students, C)
	}

	m := map[int][]int{1: []int{}, 2: []int{}, 3: []int{}}

	for index, student := range students {
		m[student] = append(m[student], index)
	}
	teams := 1000000
	for _, v := range m {
		teams = min(teams, len(v))
	}
	fmt.Printf("%d\n", teams)
	if teams == 0 {
		return
	}

	for i := 0; i < teams; i++ {
			fmt.Printf("%d %d %d\n", m[1][i], m[2][i], m[3][i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
type Team struct {
	id uint32
	loc []uint32
}

func main() {
	var n, c1,c2,c3 uint32
	var t uint32
	m := make(map[uint32]Team)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i:= uint32(0); i < n; i++{
		fmt.Fscanf(in, "%d", &t)
		var team Team
		team = m[t]
		team.id++
		if t == 1{
			c1++
		}else if t == 2{
			c2++
		}else if t ==3{
			c3++
		}
		team.loc = append(team.loc, i)
		m[t] = team
	}
	if c1 != 0 && c2 != 0 && c3 != 0{
		c := c1 + c2 + c3
		c = c/3
		fmt.Println(c)
		for i:=uint32(0); i < c; i++{
			if c1 == 0 || c2 == 0 || c3 == 0{
				break
				fmt.Println()
			}
			for _, v := range m {
				fmt.Print(v.loc[0] + 1," ")
				RemoveIndex(v.loc, 0)
			}
			c1--
			c2--
			c3--
			fmt.Println()
		}
	}else{
		fmt.Println(0)
	}
}
func RemoveIndex(s []uint32, index uint32) []uint32 {
    return append(s[:index], s[index+1:]...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
type Team struct {
	id uint16
	loc []uint16
}

func main() {
	var n, c1,c2,c3 uint16
	var t uint16
	m := make(map[uint16]Team)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i:= uint16(0); i < n; i++{
		fmt.Fscanf(in, "%d", &t)
		var team Team
		team = m[t]
		team.id++
		if t == 1{
			c1++
		}else if t == 2{
			c2++
		}else if t ==3{
			c3++
		}
		team.loc = append(team.loc, i)
		m[t] = team
	}
	if c1 != 0 && c2 != 0 && c3 != 0{
		c := c1 + c2 + c3
		c = c/3
		fmt.Println(c)
		for i:=uint16(0); i < c; i++{
			for _, v := range m {
				fmt.Print(v.loc[0] + 1," ")
				RemoveIndex(v.loc, 0)
			}
			fmt.Println()
		}
	}else{
		fmt.Println(0)
	}
}
func RemoveIndex(s []uint16, index uint16) []uint16 {
    return append(s[:index], s[index+1:]...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
type Team struct {
	id uint16
	loc []uint16
}

func main() {
	var n, c1,c2,c3 uint16
	var t uint16
	m := make(map[uint16]Team)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i:= uint16(0); i < n; i++{
		fmt.Fscanf(in, "%d", &t)
		var team Team
		team = m[t]
		team.id++
		if t == 1{
			c1++
		}else if t == 2{
			c2++
		}else if t ==3{
			c3++
		}
		team.loc = append(team.loc, i)
		m[t] = team
	}
	if c1 != 0 && c2 != 0 && c3 != 0{
		c := c1 + c2 + c3
		c = c/3
		fmt.Println(c)
		for i:=uint16(0); i < c; i++{
			if c1 == 0 || c2 == 0 || c3 == 0{
				break
				fmt.Println()
			}
			for _, v := range m {
				fmt.Print(v.loc[0] + 1," ")
				RemoveIndex(v.loc, 0)
			}
			c1--
			c2--
			c3--
			fmt.Println()
		}
	}else{
		fmt.Println(0)
	}
}
func RemoveIndex(s []uint16, index uint16) []uint16 {
    return append(s[:index], s[index+1:]...)
}


package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	d := in.NextInt()
	h := in.NextInt()
	if d-h > h || (d == 1 && n != 2) {
		fmt.Fprintln(out, -1)
		return
	}
	addBranch(h)
	n -= h + 1
	if d == h {
		for n > 0 {
			fmt.Fprintln(out, 2, nextVertex())
			n--
		}
		return
	}
	for n > 0 {
		k := d - h
		if k > n {
			k = n
		}
		addBranch(k)
		n -= k
	}
}

func addBranch(h int) {
	p := 1
	for h > 0 {
		v := nextVertex()
		fmt.Fprintln(out, p, v)
		p = v
		h--
	}
}

var vertex = 1

func nextVertex() int {
	vertex++
	return vertex
}

type Edge struct {
	a, b int
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	for len(r.buf) == 0 {
		var buf bytes.Buffer
		for {
			chunk, more, _ := r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}

package main

import (
	"fmt"
)

func main() {
	N,D,H,n,i,src := 0,0,0,0,0,0
	fmt.Scanf("%d %d %d\n", &N, &D, &H)
	if 2*H < D || H > D || (H == 1 && D == 1 && N > 2){
		fmt.Printf("-1\n")
		return
	}
	for n=2; n<=H+1; n++ {
		fmt.Printf("%d %d\n", n-1,n)
	}
	if H < D {
		H = D-H
		src = 1
	} else {
		src = 2
		H = 1
	}
	for n <= N {
		fmt.Printf("%d %d\n", src,n)
		n++
		for i=1; i<H && n<=N; i++ {
			fmt.Printf("%d %d\n", n-1,n)
			n++
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	N,D,H,n,i,src := 0,0,0,0,0,0
	fmt.Scanf("%d %d %d\n", &N, &D, &H)
	if 2*H < D || H > D {
		fmt.Printf("-1\n")
		return
	}
	for n=2; n<=H+1; n++ {
		fmt.Printf("%d %d\n", n-1,n)
	}
	if H < D {
		H = D-H
		src = 1
	} else {
		src = 2
		H = 1
	}
	for n <= N {
		fmt.Printf("%d %d\n", src,n)
		n++
		for i=1; i<H && n<=N; i++ {
			fmt.Printf("%d %d\n", n-1,n)
			n++
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	N,D,H,n,i := 0,0,0,0,0
	fmt.Scanf("%d %d %d\n", &N, &D, &H)
	if 2*H < D || H > D {
		fmt.Printf("-1\n")
		return
	}
	for n=2; n<=H+1; n++ {
		fmt.Printf("%d %d\n", n-1,n)
	}
	if H < D {
		H = D-H
	}
	for n <= N {
		fmt.Printf("1 %d\n", n)
		n++
		for i=1; i<H && n<=N; i++ {
			fmt.Printf("%d %d\n", n-1,n)
			n++
		}
	}
}

package main

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

var edges []Edge
var n int

func main() {
	defer out.Flush()
	n = in.NextInt()
	d := in.NextInt()
	h := in.NextInt()
	if d > 2*h || (d == h && d != n-1) {
		fmt.Fprintln(out, -1)
		return
	}
	addBranch(h)
	n -= h + 1
	for n > 0 {
		k := d - h
		if k > n {
			k = n
		}
		addBranch(k)
		n -= k
	}
	for _, e := range edges {
		fmt.Fprintln(out, e.a, e.b)
	}
}

func addBranch(h int) {
	p := 1
	for h > 0 {
		v := nextVertex()
		edges = append(edges, Edge{p, v})
		p = v
		h--
	}
}

var vertex = 1

func nextVertex() int {
	vertex++
	return vertex
}

type Edge struct {
	a, b int
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	for len(r.buf) == 0 {
		var buf bytes.Buffer
		for {
			chunk, more, _ := r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


package main

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

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

	var T, a, b, c int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b, &c)
		Fprintln(out, max(max(a, b), c))
	}
}

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

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	printf("%d\n", nextLong()+nextLong()+nextLong()-1)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	var t int
	var a, b, c int64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(a + b + c - 1)
	}
}

package main
import (
	"fmt"
)
func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b, c, ans int64

		fmt.Scan(&a, &b, &c)
		ans = a + b + c - 1
		fmt.Println(ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff >= 0 {
			fmt.Println(diff + 1)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a, b, c int64) int64 {
	if ans, ok := calc(a, b, c); ok {
		return ans
	}
	if ans, ok := calc(b, a, c); ok {
		return ans
	}
	ans, _ := calc(c, a, b)
	return ans
}

func calc(a_, b_, c_ int64) (int64, bool) {
	a, b, c := float64(a_), float64(b_), float64(c_)

	x := -a*a + b*b + c*c
	y := 2 * b * c

	var l, r int64
	if x < y {
		l = 1
	} else {
		l = int64(math.Ceil(math.Sqrt(x - y)))
		if l == 0 {
			l = 1
		}
	}
	r = int64(math.Sqrt(x + y))

	ans := l
	return ans, l <= ans && ans <= r
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a, b, c int64) int64 {
	return a + b + c - 1
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	var a =make([]int,3,3)
	fmt.Scan(&t)
	for cs:=1;cs<=t;cs++ {
		for i:=0;i<3;i++ {
			fmt.Scan(&a[i])
		}
		sort.Ints(a)
		var c=a[2]-a[0]+1
		c=c+a[1]-1
		fmt.Println(c)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b, c int64
		fmt.Fscan(reader, &a, &b, &c)

		fmt.Println(a + b + c - 1)
	}
}

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 (
	"fmt"
	"math"
)

func main () {

	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Scan(&a)
		fmt.Scan(&b)
		fmt.Scan(&c)

		fmt.Println(int(math.Sqrt(math.Pow(float64(a-c), 2) + math.Pow(float64(b), 2)))+1)
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	printf("%d\n", nextInt()+nextInt()+nextInt()-1)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	var t, a, b, c int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(a + b + c - 1)
	}
}

package main
import (
	"fmt"
)
func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b, c int

		fmt.Scan(&a, &b, &c)
		ans := a + b + c - 1
		fmt.Println(ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		fmt.Println(a)
		diff := a[2] - a[1] - a[0]
		if diff >= 0 {
			fmt.Println(diff + 1)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(1)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff < 0 {
			fmt.Println(diff)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff <= 2 {
			fmt.Println(diff + 2)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a_, b_, c_ int64) int64 {
	a, b, c := float64(a_), float64(b_), float64(c_)
	v := -a*a + b*b + c*c - 2*b*c
	if v == 0 {
		return 1
	}
	l := math.Sqrt(v)
	return int64(math.Ceil(l))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(reader, &a, &b, &c)

		fmt.Println(a + b + c - 1)
	}
}

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"
	"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 int
		fmt.Fscan(in, &n)

		var s string
		fmt.Fscan(in, &s)

		f := true
		for i := 0; i < n / 2; i++ {
			x1, x2 := s[i] + 1, s[i] - 1
			if s[i] == 'a' {
				x2 += 2
			} else if s[i] == 'z' {
				x1 -= 2
			}
			y1, y2 := s[len(s)-i-1] + 1, s[len(s)-i-1] - 1
			if s[len(s)-i-1] == 'a' {
				y2 += 2
			} else if s[len(s)-i-1] == 'z' {
				y1 -= 2
			}
			if x1 != y1 && x1 != y2 && x2 != y1 && x2 != y2 {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
		out.Flush()

	}

}

package main

import "fmt"

func main(){
    var t int
    fmt.Scanf("%d ",&t)
    for q:=0;q<t;q++{
        var n  int
        fmt.Scanf("%d ",&n)
        var s string
        fmt.Scanf("%s ",&s)
        fl:=1
        for i:=0;i<n/2;i++ {
            j:=n-1-i;
            var si,sj int
            si=int(s[i])
            sj=int(s[j])
            if -2==si-sj||si-sj==2||si==sj {

            }else{
                fl=0
            }
        }
        if fl>0 {
            fmt.Println("YES")
        }else {

            fmt.Println("NO")
        }
    }
}

package main

import (
	"fmt"
	"math"
)

func check(s string, len int) bool {
	for i := 0; i < len/2; i++ {
		var firstchar int
		var secondchar int
		firstchar = int(s[i])
		secondchar = int(s[len-i-1])
		dif := math.Abs(float64(firstchar) - float64(secondchar))
		if dif != 2 && dif != 0 {
			return false
		}
	}
	return true
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var len int
		var s string
		fmt.Scanf("%d\n", &len)
		fmt.Scanf("%s\n", &s)
		checkresult := check(s, len)
		if checkresult == true {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64, err error){
  if !scanner.Scan() {
    return 0, scanner.Err()
  }
  return strconv.ParseInt(scanner.Text(), 10, 32)
}

func next_str()(result string, err error){
  if !scanner.Scan() {
    return string(""), scanner.Err()
  }
  return scanner.Text(), nil
}

func update_range(ch byte) (lb byte, ub byte) {
  if (ch == 'a') {
    return 'A', 'b'
  }
  if (ch == 'z') {
    return 'y', 'Z'
  }
  return ch - 1 , ch + 1
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  tests, _ := next_int()
  for i := int64(1) ; i <= tests; i++ {
    next_int()
    str, _ := next_str()
    var possible bool = true
    var last int = len(str) - 1
    for j := 0; j < last; j++ {
      flb, fub := update_range(str[j])
      slb, sub := update_range(str[last])
      if !(flb == slb || flb == sub || fub == slb || fub == sub) {
        possible = false;
        break;
      }
      last--;
    }
    if possible {
      fmt.Println("YES")
    }else{
      fmt.Println("NO")
    }
  }
}

package main

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

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

	nStrs := readInt(r)
	for i := 0; i < nStrs; i++ {
		l := readInt(r)
		s := readString(r, l)
		if check(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func check(s string) bool {
	if len(s) == 0 {
		return true
	}

	for i := 0; i <= (len(s) - 1) / 2; i++ {
		f := s[i]
		l := s[len(s)-1-i]
		if !intersects(getChars(f), getChars(l)) {
			return false
		}
	}
	return true
}

func getChars(b byte) []byte {
	if b == 'a' {
		return []byte{'b'}
	} else if b == 'z' {
		return []byte{'y'}
	} else {
		return []byte{b -1, b +1}
	}
}

func intersects(bs1 []byte, bs2 []byte) bool {
	for _, b1 := range bs1 {
		for _, b2 := range bs2 {
			if b1 == b2 {
				return true
			}
		}
	}
	return false
}

// read utils
func readInt(reader *bufio.Reader) int {
	nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)
	n := int(nTemp)
	return n
}

func readString(reader *bufio.Reader, l int) string {
	sTemp := readLine(reader)
	return sTemp[:l]
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

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

package main

import "fmt"

func main (){
    var T int
    fmt.Scan(&T)
    for I:=0; I<T; I++ {
        var n int
        var s string
        fmt.Scan(&n, &s)
        fail := false
        for i:=0; i<n/2; i++ {
            j := n-i-1
            x := int(s[i]) - int(s[j])
            if x != -2 && x != 2 && x != 0 {
                fail = true
            }
        }
        if !fail {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

import "fmt"

func isPalindrome(input string) bool {
	for i := 0; i < len(input)/2; i++ {
		if input[i] != input[len(input)-i-1] {
			return false
		}
	}
	return true
}

func newLetter(letter string, test int) string {
	asciiBytes := []byte(letter)
	if test == -1 {
		if letter == "a" {
			return "a"
		}
		return string(asciiBytes[0] - 1)

	}
	if test == 1 {
		if letter == "z" {
			return "z"
		}
		return string(asciiBytes[0] + 1)
	}
	return letter
}

func generateString(s string, l int) bool {
	j := l - 1
	for i := 0; i < l/2; i += 1 {
		if s[i] != s[j] {
			var t1 string = newLetter(string(s[i]), 1)
			var t2 string = newLetter(string(s[j]), -1)
			if t1 != t2 {
				t1 = newLetter(string(s[i]), -1)
				t2 = newLetter(string(s[j]), 1)
				if t1 != t2 {
					return false
				}
			}
		}
		j -= 1
		if i == l/2 && j == l/2 {
			return true
		}
	}
	return true
}

func isTrue(len int, s string) bool {
	if isPalindrome(s) {
		return true
	}
	return generateString(s, len)
}

func out(a bool) string {
	if a {
		return "YES"
	}
	return "NO"
}
func main() {
	//Input
	var t int
	fmt.Scanf("%d", &t)
	a := make([]int, t)
	b := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a[i], &b[i])
	}

	for i := 0; i < t; i++ {
		fmt.Println(out(isTrue(a[i], b[i])))
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscan(reader, &T)

	for T > 0 {
		var (
			ln int
			st string
		)

		fmt.Fscan(reader, &ln, &st)
		cont := true
		for i := 0; i < ln/2; i++ {

			if st[i]+1 != st[ln-i-1]-1 && st[i]-1 != st[ln-i-1]+1 && st[i]+1 != st[ln-i-1]+1 && st[i]-1 != st[ln-i-1]-1 {
				fmt.Println("NO")
				cont = false
				break
			}
		}
		if cont {
			fmt.Println("YES")
		}
		T--
	}
}

//go 1.6

package main
import "fmt"
func main() {
	var n int
	var o []string
	fmt.Scan(&n)
	for i:= 0;i<n;i++{
		var l int
		var s string
		fmt.Scan(&l,&s)
		b := []byte(s)
		f := true
		for j:=0;j<l/2;j++{
			if !(b[j] == b[l-j-1] || b[j]-1== b[l-j-1]+1 || b[j]+1 == b[l-j-1]-1) {
				f = false
			}
		}
		if f {
			s = "YES"
		}  else{
			s = "NO"
		}
		o =append(o,s)
	}
	for _,a := range o {
	fmt.Println(a)
	}
}

package main

import (
    "fmt"
    "math"
)

func check(s string, len int) bool {
    for i:=0; i<len/2; i++ {
        fistChar := int(s[i])
        lastChar := int(s[len-1-i])
        dif := math.Abs(float64(fistChar - lastChar))

        if dif != 2 && dif != 0 {
            return false
        }
    }
    return true
}

func main() {
    var n int

    fmt.Scanf("%d\n", &n)

    for i:=0; i<n; i ++ {
        var len int
        var s string

        fmt.Scanf("%d\n", &len)
        fmt.Scanf("%s\n", &s)

        //fmt.Printf("str:%s len:%d\n", s, len)

        boolResult := check(s, len)

        if boolResult == true {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }

}

package main

import "fmt"

func main(){
    var t int
    fmt.Scanf("%d ",&t)
    for q:=0;q<t;q++{
        var n  int
        fmt.Scanf("%d ",&n)
        var s string
        fmt.Scanf("%s ",&s)
        fl:=1
        for i:=0;i<n/2;i++ {
            j:=n-1-i;
            var si,sj int
            si=int(s[i])
            sj=int(s[j])
            if -2<=si-sj&&si-sj<=2 {

            }else{
                fl=0
            }
        }
        if fl>0 {
            fmt.Println("YES")
        }else {

            fmt.Println("NO")
        }
    }
}

package main

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

func main()  {

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

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

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

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

		var s string
		fmt.Fscan(in, &s)

		f := true
		for i := 0; i < len(s) / 2; i++ {
			x1, x2 := s[i] + 1, s[i] - 1
			if s[i] == 'a' {
				x2 += 2
			} else if s[i] == 'z' {
				x1 -= 2
			}
			y1, y2 := s[len(s)-i-1] + 1, s[len(s)-i-1] - 1
			if s[i] == 'a' {
				y2 += 2
			} else if s[i] == 'z' {
				y1 -= 2
			}
			if x1 != y1 && x1 != y2 && x2 != y1 && x2 != y2 {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}

}

//go 1.6

package main
import "fmt"
func main() {
	var n int
	var o []string
	fmt.Scan(&n)
	for i:= 0;i<n;i++{
		var l int
		var s string
		fmt.Scan(&l,&s)
		b := []byte(s)
		f := true
		for j:=0;j<l/2;j++{
			if !(b[j] == b[l-j-1] || b[j]-1== b[l-j-1]+1 || b[j]+1 == b[l-j-1]-1) {
				f = false
			}
		}
		if f {
			s = "YES"
		}  else{
			s = "NO"
		}
		o =append(o,s)
	}
	for _,a := range o {
	fmt.Printf(a)
	}
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = math.MinInt64
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"container/heap"
)

const (
	maxn = 1000+5
	maxm = 1000+5
	maxk = 1000000+5
)

type IntHeap []int64
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int64))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var (
	ar [maxn][maxm]int
	row IntHeap
	col IntHeap
	rowv [maxk]int64
	colv [maxk]int64
)

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

	var n, m, k, p int
	fmt.Fscan(in, &n, &m, &k, &p)

	row = make(IntHeap, n)
	col = make(IntHeap, m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &ar[i][j])
			row[i] += int64(ar[i][j])
			col[j] += int64(ar[i][j])
		}
	}

	// fmt.Println(row)
	// fmt.Println(col)

	heap.Init(&row)
	heap.Init(&col)
	for i := 1; i <= k; i++ {
		v := heap.Pop(&row).(int64)
		rowv[i] = rowv[i-1] + v
		heap.Push(&row, v-int64(p*m))

		v = heap.Pop(&col).(int64)
		colv[i] = colv[i-1] + v
		heap.Push(&col, v-int64(p*n))
	}

	// for i := 0; i < 10; i++ {
	// 	fmt.Print(rowv[i], " ")
	// }
	// fmt.Println()
	// for i := 0; i < 10; i++ {
	// 	fmt.Print(colv[i], " ")
	// }
	// fmt.Println()

	res := int64(-1000000000000000000)
	for i := 0; i <= k; i++ {
		v := rowv[i] + colv[k-i] - int64(i)*int64(k-i)*int64(p)
		if v > res {
			res = v
		}
	}
	fmt.Fprintln(out, res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int, n)
	col := make([]int, m)
	for i := 0; i < n; i++ {
		var v int
		for j := 0; j < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_heap := &IntHeap{}
	col_heap := &IntHeap{}
	heap.Init(row_heap)
	heap.Init(col_heap)
	for i := 0; i < n; i++ {
		heap.Push(row_heap, row[i])
	}
	for j := 0; j < m; j++ {
		heap.Push(col_heap, col[j])
	}
	var row_reduce, col_reduce, res int = 0, 0, 0
	for i := 0; i < k; i++ {
		row_val := (*row_heap)[0] - row_reduce
		col_val := (*col_heap)[0] - col_reduce
		if row_val > col_val {
			res += row_val
			heap.Pop(row_heap)
			heap.Push(row_heap, row_val-p*n)
			col_reduce += p
		} else {
			res += col_val
			heap.Pop(col_heap)
			heap.Push(col_heap, col_val-p*m)
			row_reduce += p
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*n)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, p, k)
	col_val := Run(col, m, p, k)
	var res int64 = -1000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}


package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type pair struct {
	v   int
	dis int64
}
type hp []pair

func (h hp) Len() int              { return len(h) }
func (h hp) Less(i, j int) bool    { return h[i].dis < h[j].dis }
func (h hp) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *hp) Push(v interface{})   { *h = append(*h, v.(pair)) }
func (h *hp) Pop() (v interface{}) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; return }
func (h *hp) push(v pair)          { heap.Push(h, v) }
func (h *hp) pop() pair            { return heap.Pop(h).(pair) }

func CF1473E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, m, v, w, wt int
	Fscan(in, &n, &m)
	type nb struct{ to, wt int }
	g := make([][]nb, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w, &wt)
		v--
		w--
		g[v] = append(g[v], nb{w, wt})
		g[w] = append(g[w], nb{v, wt})
	}

	const inf int64 = 1e18
	dis := make([]int64, n*4)
	for i := range dis {
		dis[i] = inf
	}
	dis[0] = 0
	h := hp{{}}
	for len(h) > 0 {
		p := h.pop()
		x := p.v
		if dis[x] < p.dis {
			continue
		}
		pp := x >> 1 & 1
		q := x & 1
		for _, e := range g[x>>2] {
			w, wt := e.to, int64(e.wt)
			y := w<<2 | pp<<1 | q
			if newD := dis[x] + wt; newD < dis[y] {
				dis[y] = newD
				h.push(pair{y, newD})
			}
			if newD := dis[x] + wt*2; q == 0 && newD < dis[y|1] {
				dis[y|1] = newD
				h.push(pair{y | 1, newD})
			}
			if newD := dis[x]; pp == 0 && newD < dis[y|2] {
				dis[y|2] = newD
				h.push(pair{y | 2, newD})
			}
		}
	}
	for i := 1; i < n; i++ {
		Fprint(out, min(dis[i<<2], dis[i<<2|3]), " ")
	}
}

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

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

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type pair73 struct {
	v int
	d int64
}
type hp73 []pair73

func (h hp73) Len() int              { return len(h) }
func (h hp73) Less(i, j int) bool    { return h[i].d < h[j].d }
func (h hp73) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *hp73) Push(v interface{})   { *h = append(*h, v.(pair73)) }
func (h *hp73) Pop() (v interface{}) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; return }
func (h *hp73) push(v pair73)        { heap.Push(h, v) }
func (h *hp73) pop() pair73          { return heap.Pop(h).(pair73) }

func CF1473E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var n, m, v, w, wt int
	Fscan(in, &n, &m)
	type nb struct{ to, wt int }
	g := make([][]nb, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w, &wt)
		v--
		w--
		g[v] = append(g[v], nb{w, wt})
		g[w] = append(g[w], nb{v, wt})
	}

	const inf int64 = 1e18
	dis := make([]int64, n*4)
	for i := range dis {
		dis[i] = inf
	}
	dis[0] = 0
	h := hp73{{}}
	for len(h) > 0 {
		pd := h.pop()
		x := pd.v
		if dis[x] < pd.d {
			continue
		}
		// 分成四层，分别表示原图、不算最大值、额外再算一遍最小值、不算最大值且额外再算一遍最小值
		// 从第一层到第四层就是要求的最短路
		// 即便当前的边不是最小或最大，后面转移的时候也会覆盖掉
		for _, e := range g[x>>2] {
			w, wt := e.to, int64(e.wt)
			y := w<<2 | x&3
			if newD := dis[x] + wt; newD < dis[y] {
				dis[y] = newD
				h.push(pair73{y, newD})
			}
			if newD := dis[x] + wt*2; x&1 == 0 && newD < dis[y|1] {
				dis[y|1] = newD
				h.push(pair73{y | 1, newD})
			}
			if newD := dis[x]; x>>1&1 == 0 && newD < dis[y|2] {
				dis[y|2] = newD
				h.push(pair73{y | 2, newD})
			}
		}
	}
	for i := 1; i < n; i++ {
		Fprint(out, min(dis[i<<2], dis[i<<2|3]), " ")
	}
}

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


package main

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

type pride struct {
	n   int
	arr []int
}

func (c *pride) readInput() {
	scanner := bufio.NewReader(os.Stdin) // read n and m
	fmt.Fscanf(scanner, "%d\n", &c.n)

	c.arr = make([]int, c.n)
	for i := range c.arr {
		fmt.Fscanf(scanner, "%d", &c.arr[i])
	}
}

func (c *pride) solve() int {
	n, arr := c.n, c.arr

	var gcdTmp, gcdAll int
	var i, j, min int

	// count number of 1
	count1 := 0
	for i = range arr {
		if arr[i] == 1 {
			count1++
		}
	}
	if count1 > 0 {
		return n - count1
	}

	// check all gcd
	for gcdAll, i = arr[0], 1; i < n; i++ {
		gcdAll = gcd(arr[i], gcdAll)
	}
	if gcdAll > 1 {
		return -1
	}

	// find continuous subarray has gcd = 1 with min length
	for min, i = n+1, 1; i < n; i++ {
		for gcdTmp, j = arr[i], i-1; j >= 0; j-- {
			if gcdTmp = gcd(arr[j], gcdTmp); gcdTmp == 1 {
				if i-j < min {
					min = i - j
				}
			}
		}
	}

	return n - 1 + min
}

func gcd(a, b int) int {
	if a == 1 || b == 1 {
		return 1
	}

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

	for b != 0 {
		a, b = b, a%b
	}

	return a
}

func main() {
	var p pride
	p.readInput()
	fmt.Print(p.solve())
}

/*
URL:
https://codeforces.com/problemset/problem/891/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n int
	A []int
)

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

	one := sub()
	if one > 0 {
		fmt.Println(n - one)
		return
	}

	diff := INF_BIT30
	for i := 0; i < n; i++ {
		g := A[i]
		for j := i + 1; j < n; j++ {
			g = Gcd(g, A[j])
			if g == 1 {
				ChMin(&diff, j-i)
			}
		}
	}

	if diff < INF_BIT30 {
		fmt.Println(diff + n - 1)
	} else {
		fmt.Println(-1)
	}
}

func sub() int {
	res := 0
	for i := 0; i < n; i++ {
		if A[i] == 1 {
			res++
		}
	}
	return res
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a < 0 || b < 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}

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

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	cnt1 := 0
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			cnt1++
		}
	}
	if cnt1 > 0 {
		fmt.Println(n - cnt1)
		return
	}
	best := 100000
	for i := 0; i < n; i++ {
		h := a[i]
		for j := i + 1; j < n; j++ {
			h = gcd(h, a[j])
			if h == 1 {
				best = min(best, j-i+n-1)
			}
		}
	}
	if best == 100000 {
		fmt.Println(-1)
	} else {
		fmt.Println(best)
	}
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/891/A

package main

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func Solve(n int, a []int) int {
	ones := 0
	for _, elem := range a {
		if elem == 1 {
			ones += 1
		}
	}
	if ones > 0 {
		return n - ones
	}
	best := math.MaxInt32
	for i, elem := range a {
		d := elem
		for j := i - 1; j >= 0; j-- {
			d = gcd(d, a[j])
			if d == 1 && i-j < best {
				best = i - j
			}
		}
	}
	if best == math.MaxInt32 {
		return -1
	}
	return best + n - 1
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

package main

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

type pride struct {
	n   int
	arr []int
}

func (c *pride) readInput() {
	scanner := bufio.NewReader(os.Stdin) // read n and m
	fmt.Fscanf(scanner, "%d\n", &c.n)

	c.arr = make([]int, c.n)
	for i := range c.arr {
		fmt.Fscanf(scanner, "%d", &c.arr[i])
	}
}

func (c *pride) solve() int {
	n, arr := c.n, c.arr

	var gcdTmp, gcdAll int
	var i, j, min int

	// count number of 1
	count1 := 0
	for i = range arr {
		if arr[i] == 1 {
			count1++
		}
	}
	if count1 > 0 {
		return n - count1
	}

	// check all gcd
	for gcdAll, i = arr[0], 1; i < n; i++ {
		gcdAll = gcd(arr[i], gcdAll)
	}
	if gcdAll > 1 {
		return -1
	}

	// find continuous subarray has gcd = 1 with min length
	for min, i = n+1, 1; i < n; i++ {
		for gcdTmp, j = arr[i], i-1; j >= 0; j-- {
			if gcdTmp = gcd(arr[j], gcdTmp); gcdTmp == 1 {
				if i-j < min {
					min = i - j
				}
				break
			}
		}
	}

	return n - 1 + min
}

func gcd(a, b int) int {
	if a == 1 || b == 1 {
		return 1
	}

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

	for b != 0 {
		a, b = b, a%b
	}

	return a
}

func main() {
	var p pride
	p.readInput()
	fmt.Print(p.solve())
}

package main

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

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	for i := 1; i < n; i++ {
		if a[i-1] != a[i] {
			if gcd(a[i-1], a[i]) == 1 {
				fmt.Println(n)
				return
			} else if i >= 2 && gcd(a[i-2], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			} else if i+1 < n && gcd(a[i+1], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			}
		}
	}
	fmt.Println(-1)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

func max(a, b int64) int64 {
	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"
	"os"
	"strconv"
)

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			fmt.Println(n - 1)
		}
	}
	for i := 1; i < n; i++ {
		if a[i-1] != a[i] {
			if gcd(a[i-1], a[i]) == 1 {
				fmt.Println(n)
				return
			} else if i >= 2 && gcd(a[i-2], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			} else if i+1 < n && gcd(a[i+1], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			}
		}
	}
	fmt.Println(-1)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

func max(a, b int64) int64 {
	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"
	"os"
	"strconv"
)

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	cnt1 := 0
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			cnt1++
		}
	}
	if cnt1 > 0 {
		fmt.Println(n - cnt1)
		return
	}
	for i := 1; i < n; i++ {
		if a[i-1] != a[i] {
			if gcd(a[i-1], a[i]) == 1 {
				fmt.Println(n)
				return
			} else if i >= 2 && gcd(a[i-2], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			} else if i+1 < n && gcd(a[i+1], gcd(a[i-1], a[i])) == 1 {
				fmt.Println(n + 1)
				return
			}
		}
	}
	fmt.Println(-1)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

func max(a, b int64) int64 {
	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"
	"os"
	"strconv"
)

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	cnt1 := 0
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			cnt1++
		}
	}
	if cnt1 > 0 {
		fmt.Println(n - cnt1)
		return
	}
	best := 100000
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if gcd(a[i], a[j]) == 1 {
				best = min(best, j-i+n-1)
			}
		}
	}
	if best == 100000 {
		fmt.Println(-1)
	} else {
		fmt.Println(best)
	}
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/891/A

package main

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

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

func Solve(n int, a []int) int {
	ones := 0
	for _, elem := range a {
		if elem == 1 {
			ones += 1
		}
	}
	if ones > 0 {
		return n - ones
	}
	best := math.MaxInt32
	for i, elem := range a {
		for j := i + 1; j < n; j++ {
			d := gcd(elem, a[j])
			if d == 1 {
				best = min(best, j-i)
			}
		}
	}
	if best == math.MaxInt32 {
		return -1
	}
	return best + n - 1
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/891/A

package main

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

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

func Solve(n int, a []int) int {
	ones := 0
	coprime := false
	triplet := []int{}
	middle := 1
	tripletAnswer := math.MaxInt32
	for i, elem := range a {
		if elem == 1 {
			ones += 1
		}
		if i+1 <= n-1 {
			d := gcd(a[i], a[i+1])
			if d == 1 {
				coprime = true
			}
		}
		if len(triplet) == 2 && triplet[len(triplet)-1] == elem {
			middle += 1
		} else if len(triplet) == 0 || (len(triplet) != 3 && triplet[len(triplet)-1] != elem) {
			triplet = append(triplet, elem)
		}
		if len(triplet) == 3 {
			x := gcd(triplet[0], triplet[1])
			y := gcd(triplet[1], triplet[2])
			if gcd(x, y) == 1 {
				tripletAnswer = min(tripletAnswer, n+middle)
			}
			triplet = []int{triplet[1], triplet[2]}
			middle = 1
		}
	}
	if ones > 0 {
		return n - ones
	} else if coprime {
		return n
	} else if tripletAnswer == math.MaxInt32 {
		return -1
	}
	return tripletAnswer
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/891/A

package main

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

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

func Solve(n int, a []int) int {
	ones := 0
	coprime := false
	triplet := []int{}
	middle := 1
	tripletAnswer := math.MaxInt32
	for i, elem := range a {
		if elem == 1 {
			ones += 1
		}
		if i+1 <= n-1 {
			d := gcd(a[i], a[i+1])
			if d == 1 {
				coprime = true
			}
		}
		if len(triplet) == 2 && triplet[len(triplet)-1] == elem {
			middle += 1
		} else if len(triplet) == 0 || (len(triplet) != 3 && triplet[len(triplet)-1] != elem) {
			triplet = append(triplet, elem)
		}
		if len(triplet) == 3 {
			x := gcd(triplet[0], triplet[1])
			y := gcd(triplet[1], triplet[2])
			if gcd(x, y) == 1 {
				tripletAnswer = min(tripletAnswer, n+middle)
			}
			triplet = []int{triplet[2]}
			middle = 1
		}
	}
	if ones > 0 {
		return n - ones
	} else if coprime {
		return n
	} else if tripletAnswer == math.MaxInt32 {
		return -1
	}
	return tripletAnswer
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}