It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile. The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot. The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

NoteFor the sample input:  The worms with labels from [1, 2] are in the first pile.  The worms with labels from [3, 9] are in the second pile.  The worms with labels from [10, 12] are in the third pile.  The worms with labels from [13, 16] are in the fourth pile.  The worms with labels from [17, 25] are in the fifth pile.

// https://codeforces.com/contest/474/problem/B

package main

import (
	"bufio"
	"fmt"
	"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...) }

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	arr := make([]int64, n+5)
	for i:=0;i<n;i++ {
		if i==n-1 {
			scanf("%d\n", &arr[i])
		} else {
			scanf("%d ", &arr[i])
		}
	}

	vl := make([]int64, 0)
	var sum int64
	for i:=0;i<n;i++ {
		sum += arr[i]
		if i==0 {
			vl = append(vl, 1)
			vl = append(vl, sum)
		} else {
			vl = append(vl, vl[len(vl)-1]+1)
			vl = append(vl, sum)
		}
	}

	var m int
	scanf("%d\n", &m)
	for i:=0;i<m;i++ {
		var temp int64
		scanf("%d ", &temp)
		ans := false
		l := 0
		r := len(vl)-1
		for l<=r {
			mid := l + ((r-l)/2)
			if vl[mid] == temp {
				mid++
				ans = true
				if mid%2 == 0 {
					printf("%d\n", mid/2)
				} else {
					printf("%d\n", (mid/2)+1)
				}
				break
			}
			if vl[mid] < temp {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if !ans {
			l++
			if l%2 == 0 {
				printf("%d\n", l/2)
			} else {
				printf("%d\n", (l/2)+1)
			}
		}
	}
}

package main

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

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

func main() {

	defer out.Flush()
	in.Split(bufio.ScanWords)

	n := NextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = NextInt()
	}

	sum := make([]int, n)
	sum[0] = a[0]
	for i := 1; i < n; i++ {
		sum[i] = sum[i-1] + a[i]
	}

	m := NextInt()
	for test := 0; test < m; test++ {
		q := NextInt()
		var lo, hi int = -1, n
		for hi - lo > 1 {
			mid := lo + (hi - lo) / 2
			if sum[mid] < q {
				lo = mid
			}else {
				hi = mid
			}
		}
		fmt.Fprintln(out, hi + 1)
	}
}

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

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

/*
 */
var n int
var piles [100000 + 1]int
var t int

func main() {
	defer exit()
	n = nextInt()
	piles[1] = 1
	for i := 2; i != n+1; i++ {
		piles[i] = piles[i-1] + nextInt()
	}
	t = nextInt()
	t = nextInt()
	for i := 1; i != t+1; i++ {
		ts := nextInt()
		l := 1
		r := n
		for {
			if l >= r {
				break
			}
			mid := (l + r + 1) / 2
			midv := piles[mid]
			if ts < midv {
				r = mid - 1
			} else {
				l = mid
			}
		}
		fmt.Fprintln(out, l)
	}
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}
func next() string {
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

// custom
func nextInt() int {
	ret, _ := strconv.Atoi(next())
	return ret
}

/*
 */
var n int
var piles [100000 + 1]int
var t int

func main() {
	defer exit()
	n = nextInt()
	piles[1] = 1
	for i := 2; i != n+1; i++ {
		piles[i] = piles[i-1] + nextInt()
	}
	t = nextInt()
	t = nextInt()
	for i := 1; i != t+1; i++ {
		ts := nextInt()
		l := 1
		r := n
		for {
			if l >= r {
				break
			}
			mid := (l + r + 1) / 2
			midv := piles[mid]
			if ts < midv {
				r = mid - 1
			} else {
				l = mid
			}
		}
		fmt.Fprintln(out, l)
	}
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

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

/*
 */
var n int
var piles []int
var t int

func main() {
	defer exit()

	n = nextInt()
	piles = make([]int, n+1, n+1)
	piles[1] = 1
	for i := 2; i != n+1; i++ {
		piles[i] = piles[i-1] + nextInt()
	}
	t = nextInt()
	t = nextInt()
	for i := 1; i != t+1; i++ {
		ts := nextInt()
		l := 1
		r := n
		for {
			if l >= r {
				break
			}
			mid := (l + r + 1) / 2
			midv := piles[mid]
			if ts < midv {
				r = mid - 1
			} else {
				l = mid
			}
		}
		fmt.Fprintln(out, l)
	}
}

package main

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

// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
	ret, _ := strconv.Atoi(next())
	return ret
}

func nextFloat() float64 {
	ret, _ := strconv.ParseFloat(next(), 64)
	return ret
}

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	for i := 1; i < n; i++ {
		a[i] = a[i] + a[i-1]
	}
	m := nextInt()
	for i := 0; i < m; i++ {
		x := nextInt()
		l := 0
		r := n - 1
		for l < r {
			m := l + (r-l)/2
			if x > a[m] {
				l = m + 1
			} else {
				r = m
			}
		}
		fmt.Fprintln(out, r+1)
	}

}

package main

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

type pair struct {
    a, b int
}

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

    stdin := bufio.NewReader(os.Stdin)

    var n, q, t int
    fmt.Fscan(stdin, &n)

    var a = make([]pair, n)

    a[0] = pair { a: 1, b: 1 }
    fmt.Fscan(stdin, &a[0].b)
    for i := 1; i < n; i++ {
        fmt.Fscan(stdin, &t)
        a[i] = pair{
            a: a[i-1].b + 1,
            b: a[i-1].b + t,
        }
    }
    search := func (x int) int {
        var lo, hi = 0, n - 1
        for lo <= hi {
            var mid = lo + (hi - lo) / 2
            // fmt.Println("Find", x, "in", lo, mid, hi, "value", a[mid])
            if a[mid].a <= x && x <= a[mid].b {
                return mid
            }
            if x > a[mid].b {
                lo = mid + 1
            } else {
                hi = mid - 1
            }
        }
        return -1
    }

    // fmt.Println(a)

    fmt.Fscan(stdin, &q)
    for i := 0; i < q; i++ {
        fmt.Fscan(stdin, &t)
        fmt.Println(search(t) + 1)
    }

}

// hello project main.go
package main

import (
    "fmt"
    "os"
    "bufio"

)
const maxn = int (1e6 + 10)
var Hash [maxn]int
func main() {

    reader := bufio.NewReader(os.Stdin)
    var n ,m int
    fmt.Fscan(reader,&n)
   // fmt.Println("n = ",+ n)
    id := 1
    for i := 1;i <= n; i ++{
        var x int
        fmt.Fscan(reader,&x)
        for{
            x --
            if x < 0{   break }

          //  fmt.Println("id = ", + id)
            Hash[id] = i
            id ++
        }
    }
    fmt.Fscan(reader,&m)
    for{
        m --
        if m < 0{
            break
        }
        var x int
        fmt.Fscan(reader,&x)
       // fmt.Printf("x = %d\n",x)
        fmt.Println(Hash[x])

    }

}

package main

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

func cum_range(cum_worms []int64, i int64) (int64, int64) {
	if i == 0 {
		return 1, cum_worms[i]
	}
	return cum_worms[i-1] + 1, cum_worms[i]
}

func bin_search(l, r, q int64, cum_worms []int64) int64 {
	if l > r {
		return -1
	}
	mid := l + (r-l)/2
	start, end := cum_range(cum_worms, mid)
	if q >= start && q <= end {
		// q is within [start, end]
		return mid + 1
	}
	if q > end {
		// q is after end
		return bin_search(mid+1, r, q, cum_worms)
	}
	// q is before start
	return bin_search(l, mid-1, q, cum_worms)
}

// Create cumulative array cum_worms {c0, ..., ci, ci+1, ci+3, ..., cn}
// where ci is the total number of worms stored in all piles from 1 to i
// inclusive.
// Let the worm label be 'w'.
// Do binary search for 'w' in cum_worms and find pile number
// func main() {
//	reader := bufio.NewReader(os.Stdin)
//	scanner := bufio.NewScanner(os.Stdin)
//	scanner.Split(bufio.ScanWords)
//	writer := bufio.NewWriter(os.Stdout)
//	var piles int64
//	fmt.Fscanf(reader, "%d\n", &piles)
//	worm_counts := make([]int64, piles)
//	cum_worms := make([]int64, piles)
//	var i int64
//	for i = 0; i < piles; i++ {
//		scanner.Scan()
//		w, _ := strconv.Atoi(scanner.Text())
//		worm_counts[i] = int64(w)
//		cum_worms[i] = worm_counts[i]
//		if i == 0 {
//			continue
//		}
//		cum_worms[i] += cum_worms[i-1]
//	}
//	var queries int64
//	fmt.Fscanf(reader, "%d\n", &queries)
//	for i = 0; i < queries; i++ {
//		scanner.Scan()
//		q, _ := strconv.Atoi(scanner.Text())
//		fmt.Fprintf(writer, "%d\n", bin_search(0, piles-1, int64(q), cum_worms))
//	}
//	writer.Flush()
// }

// Create cumulative array cum_worms {c0, ..., ci, ci+1, ci+3, ..., cn}
// where ci is the total number of worms stored in all piles from 1 to i
// inclusive.
// Let the worm label be 'w'.
// Do binary search for 'w' in cum_worms and find pile number
func main() {
	reader := bufio.NewReader(os.Stdin)
	var piles int64
	fmt.Fscanf(reader, "%d\n", &piles)
	worm_counts := make([]int64, piles)
	cum_worms := make([]int64, piles)
	var i int64
	for i = 0; i < piles; i++ {
		fmt.Fscanf(reader, "%d", &worm_counts[i])
		cum_worms[i] = worm_counts[i]
		if i == 0 {
			continue
		}
		cum_worms[i] += cum_worms[i-1]
	}
	var queries_count int64
	fmt.Fscanf(reader, "\n%d\n", &queries_count)
	for i = 0; i < queries_count; i++ {
		var q int64
		fmt.Fscanf(reader, "%d", &q)
		fmt.Println(bin_search(0, piles-1, q, cum_worms))
	}
}

package main

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

//type PointW struct {
//	x int
//	y int
//}
//
//func main() {
//	var n int
//	fmt.Scanf("%d\n", &n)
//	a := make([]int, n)
//	aa := make([]PointW, n)
//	for i := 0; i < n; i++ {
//		fmt.Scanf("%d", &a[i])
//		//fmt.Println("a", i, "=", a[i])
//		if i == 0 {
//			aa[i] = PointW{1, a[i]}
//		} else {
//			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
//		}
//	}
//	fmt.Scanln()
//	var m int
//	fmt.Scanln(&m)
//	for i := 0; i < m; i++ {
//		var b int
//		fmt.Scanf("%d", &b)
//		fmt.Println(find(aa, b) + 1)
//	}
//}
//
//func find(aa []PointW, b int) int {
//	start := 0
//	end := len(aa) - 1
//	index := (start + end) / 2
//	for {
//		if start >= end {
//			return index
//		}
//		if aa[index].x <= b && b <= aa[index].y {
//			return index
//		}
//		if b > aa[index].y {
//			start = index + 1
//		}
//		if b < aa[index].x {
//			end = index - 1
//		}
//		index = (start + end) / 2
//	}
//}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanln(reader, &n)
	a := make([]int, n)
	var x int
	for i := 0; i < n; i++ {
		var t int
		fmt.Fscanf(reader, "%d", &t)
		x += t
		if i == 0 {
			a[i] = t
		} else {
			a[i] = a[i-1] + t
		}
	}
	aa := make([]int, x+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			for j := 1; j <= a[i]; j++ {
				aa[j] = i
			}
		} else {
			for j := a[i-1] + 1; j <= a[i]; j++ {
				aa[j] = i
			}
		}
	}
	fmt.Fscanln(reader)
	var m int
	fmt.Fscanln(reader, &m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Fscanf(reader, "%d", &b)
		fmt.Println(aa[b] + 1)
	}
}

package main

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

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

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

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

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

    n := ReadInt32()
    ans := make([]int, 1000002)

    p := 1
    z := 0
    for i := 1; i <= n; i++ {
        z = ReadInt32()
        for j := 0; j < z; j++ {
            ans[p+j] = i
        }
        p += z
    }

    m := ReadInt32()

    for i := 0; i < m; i++ {
        writer.WriteString(strconv.Itoa(ans[ReadInt32()]) + "\n")
    }
}

package main

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

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

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

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

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

    n := ReadInt32()
    ans := make([]int, 1000001)
    p := 1

    for i := 1; i <= n; i++ {
        for z := ReadInt32(); z > 0; z-- {
            ans[p] = i
            p++
        }
    }

    m := ReadInt32()
    for i := 0; i < m; i++ {
        writer.WriteString(strconv.Itoa(ans[ReadInt32()]) + "\n")
    }
}

package main

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

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

    indexn := make([]int, 1e6+1, 1e6+1)
    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    id := 1
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        for j := 0; j < a; j++ {
            indexn[id] = i+1
            id++
        }
    }

    bs.Scan()
    m, _ = strconv.Atoi(bs.Text())
    for i := 0; i < m; i++ {
        bs.Scan()
        p, _ := strconv.Atoi(bs.Text())
        fmt.Println(indexn[p])
    }
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    for i := 0; i < n; i++ {
        a[i] = nextInt()
    }
    for i := 1; i < n; i++ {
        a[i] = a[i] + a[i - 1]
    }
    m := nextInt()
    for i := 0; i < m; i++ {
        x := nextInt()
        l := 0
        r := n - 1;
        for ; l < r ; {
            m := l + (r - l) / 2
            if x > a[m] {
                l = m + 1
            } else {
                r = m;
            }
        }
        fmt.Fprintln(out, r + 1)
    }

}

package main

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

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

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

	n := nextInt()
	a := make([]int, 1000001)
	m, q := 0, 1

	for i := 1; i <= n; i++ {
		m += nextInt()

		for q <= m {
			a[q] = i
			q++
		}
	}

	m = nextInt()

	for i := 0; i < m; i++ {
		println(a[nextInt()])
	}

}

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
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

package main

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

func search(y int, xs []int) (int, int) {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m, m
		}
	}
	return r, l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		_, max := search(q, as)
		fmt.Println(max + 1)
	}

}

package main

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

func search(y int, xs []int) int {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m
		}
	}
	return l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		idx := search(q, as)
		//fmt.Println(idx + 1)
		fmt.Fprintln(out, idx+1)
		out.Flush()
	}
}

package main

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

func search(y int, xs []int) int {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m
		}
	}
	return l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		idx := search(q, as)
		//fmt.Println(idx + 1)
		fmt.Fprintln(out, idx+1)
	}
	out.Flush()
}

package main

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

func search(y int, xs []int) int {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m
		}
	}
	return l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		idx := search(q, as)
		fmt.Println(idx + 1)
	}

}

package main

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

func search(y int, xs []int) int {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m
		}
	}
	return l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		idx := search(q, as)
		fmt.Fprintln(out, idx+1)
	}
	out.Flush()
}

package main

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

func search(y int, xs []int) (int, int) {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m, m
		}
	}
	return r, l
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 8192)
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		_, max := search(q, as)
		fmt.Println(max + 1)
	}

}

package main

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

func search(y int, xs []int) int {
	n := len(xs)
	l, r := 0, n-1
	for r >= l {
		m := l + (r-l)/2
		x := xs[m]
		switch {
		case x > y:
			r = m - 1
		case x < y:
			l = m + 1
		default:
			return m
		}
	}
	return l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscan(in, &n)
	as := make([]int, n)
	last := 0
	// preprocess input
	for i := range as {
		fmt.Fscan(in, &as[i])
		as[i] += last
		last = as[i]
	}
	m := 0
	fmt.Fscan(in, &m)
	// queries
	for i := 0; i < m; i++ {
		q := 0
		fmt.Fscan(in, &q)
		idx := search(q, as)
		fmt.Fprintln(out, idx+1)
	}
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
	used bool
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var n, s int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, 1000001)
	s = 1
	for i := 1; i <= n; i++ {
		var b int
		fmt.Fscanf(reader, "%d", &b)
		for j := 0; j < b; j++ {
			a[s] = i
			s++
		}
	}
	fmt.Fscanf(reader, "\n%d\n", &n)
	for i := 0; i < n; i++ {
		var b int
		fmt.Fscanf(reader, "%d", &b)
		fmt.Println(a[b])
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

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

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

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

	n := ReadInt32()
	ans := make([]int, 1000001)
	p := 1

	for i := 1; i <= n; i++ {
		for z := ReadInt32(); z > 0; z-- {
			ans[p] = i
			p++
		}
	}

	m := ReadInt32()
	for i := 0; i < m; i++ {
		writer.WriteString(strconv.Itoa(ans[ReadInt32()]) + "\n")
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

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

	var x,y,j int
	n:= ReadInt32()
	a := make([]int,n)
	for i:=0;i<n;i++ {
		a[i] = ReadInt32()
	}
	m := ReadInt32()
	j = 0
	y = a[j]
	r := make([]string,m)
	for i:=0;i<m;i++ {
		q := ReadInt32()
		for ;y<q;{
			j++
			x =  y
			y += a[j]
		}
		for ;x>=q;{
			j--
			y =  x
			x -= a[j]
		}
		r[i] = strconv.Itoa(j+1)
	}

	fmt.Println(strings.Join(r,"\n"))

}

package main

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

type Pairs struct {
	l int
	r int
}

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, m int

	n = readInt()
	ranges := make([]Pairs, n)

	var curr, lasti int
	curr = readInt()
	ranges[0] = Pairs{1, curr}
	lasti = curr
	for i := 1; i < n; i++ {
		curr = readInt()
		ranges[i] = Pairs{lasti + ranges[i-1].l, curr + ranges[i-1].r}
		lasti = curr
	}

	m = readInt()
	var ll, rr, mid, q int
	for i := 0; i < m; i++ {
		q = readInt()

		ll = 0
		rr = n
		for ll <= rr {
			mid = (ll + rr) / 2
			if ranges[mid].l <= q && q <= ranges[mid].r {
				fmt.Fprintln(writer, mid+1)
				break
			}
			if ranges[mid].r < q {
				ll = mid + 1
			} else {
				rr = mid - 1
			}
		}
	}
}

// https://codeforces.com/contest/474/problem/B

package main

import (
	"bufio"
	"fmt"
	"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...) }

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	arr := make([]int64, n+5)
	for i:=0;i<n;i++ {
		scanf("%d ", &arr[i])
	}

	vl := make([]int64, 0)
	var sum int64
	for i:=0;i<n;i++ {
		sum += arr[i]
		if i==0 {
			vl = append(vl, 1)
			vl = append(vl, sum)
		} else {
			vl = append(vl, vl[len(vl)-1]+1)
			vl = append(vl, sum)
		}
	}

	var m int
	scanf("%d\n", &m)
	for i:=0;i<m;i++ {
		var temp int64
		scanf("%d ", &temp)
		ans := false
		l := 0
		r := len(vl)-1
		for l<=r {
			mid := l + ((r-l)/2)
			if vl[mid] == temp {
				mid++
				ans = true
				if mid%2 == 0 {
				    fmt.Println(mid/2)
				// 	printf("%d\n", mid/2)
				} else {
				    fmt.Println((mid/2)+1)
				// 	printf("%d\n", (mid/2)+1)
				}
				break
			}
			if vl[mid] < temp {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if !ans {
			l++
			if l%2 == 0 {
				fmt.Println((l/2))
				// printf("%d\n", l/2)
			} else {
			    fmt.Println((l/2)+1)
				// printf("%d\n", (l/2)+1)
			}
		}
	}
}

// https://codeforces.com/contest/474/problem/B

package main

import (
	"bufio"
	"fmt"
	"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...) }

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	arr := make([]int64, n+5)
	for i:=0;i<n;i++ {
		scanf("%d ", &arr[i])
	}

	vl := make([]int64, 0)
	var sum int64
	for i:=0;i<n;i++ {
		sum += arr[i]
		if i==0 {
			vl = append(vl, 1)
			vl = append(vl, sum)
		} else {
			vl = append(vl, vl[len(vl)-1]+1)
			vl = append(vl, sum)
		}
	}

	var m int
	scanf("%d\n", &m)
	for i:=0;i<m;i++ {
		var temp int64
		scanf("%d ", &temp)
		ans := false
		l := 0
		r := len(vl)-1
		for l<=r {
			mid := l + ((r-l)/2)
			if vl[mid] == temp {
				mid++
				ans = true
				if mid%2 == 0 {
					printf("%d\n", mid/2)
				} else {
					printf("%d\n", (mid/2)+1)
				}
				break
			}
			if vl[mid] < temp {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if !ans {
			l++
			if l%2 == 0 {
				printf("%d\n", l/2)
			} else {
				printf("%d\n", (l/2)+1)
			}
		}
	}
}

package main

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

var fi, _ = os.Open("input.txt")
var fo, _ = os.Create("output.txt")

var in = bufio.NewScanner(fi)
var out = bufio.NewWriter(fo)

func main() {

	defer out.Flush()
	in.Split(bufio.ScanWords)

	fmt.Fprintln(out)
}

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

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

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

// hello project main.go
package main

import (
    "fmt"
)
const maxn = int (1e6 + 10)
var Hash [maxn]int
func main() {

    var n ,m int
    fmt.Scanln(&n)
    var fuck rune
    fmt.Scanf("%c",&fuck)
    idex := 1
    for i := 1;i <= n; i ++{
        var x int
        fmt.Scanf("%d",&x)
        //fmt.Printf(" %d\n",x)
        for{
            x --
            if x < 0 {
                break
            }
            Hash[idex] = i
            idex ++
        }
    }
    var xu rune
    fmt.Scanf("%c",&xu)
    //fmt.Println("xu = %c",xu)
    fmt.Scanf("%d",&m)
    //fmt.Printf("%d\n",m)
    var qiang rune
    fmt.Scanf("%c",&qiang)
    for{
        m --
        if m < 0 {
            break
        }
        var x int
        fmt.Scanf("%d ",&x)
        fmt.Println(Hash[x])
    }

}

package main

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

func cum_range(cum_worms []int64, i int64) (int64, int64) {
	if i == 0 {
		return 1, cum_worms[i]
	}
	return cum_worms[i-1] + 1, cum_worms[i]
}

func bin_search(l, r, q int64, cum_worms []int64) int64 {
	if l > r {
		return -1
	}
	mid := l + (r-l)/2
	start, end := cum_range(cum_worms, mid)
	if q >= start && q <= end {
		// q is within [start, end]
		return mid + 1
	}
	if q > end {
		// q is after end
		return bin_search(mid+1, r, q, cum_worms)
	}
	// q is before start
	return bin_search(l, mid-1, q, cum_worms)
}

// Create cumulative array cum_worms {c0, ..., ci, ci+1, ci+3, ..., cn}
// where ci is the total number of worms stored in all piles from 1 to i
// inclusive.
// Let the worm label be 'w'.
// Do binary search for 'w' in cum_worms and find pile number
func main() {
	reader := bufio.NewReader(os.Stdin)
	// writer := bufio.NewWriter(os.Stdout)
	var piles int64
	fmt.Fscanf(reader, "%d\n", &piles)
	worm_counts := make([]int64, piles)
	cum_worms := make([]int64, piles)
	var i int64
	for i = 0; i < piles; i++ {
		fmt.Fscanf(reader, "%d ", &worm_counts[i])
		cum_worms[i] = worm_counts[i]
		if i == 0 {
			continue
		}
		cum_worms[i] += cum_worms[i-1]
	}
	var queries_count int64
	fmt.Fscanf(reader, "%d\n", &queries_count)
	for i = 0; i < queries_count; i++ {
		var q int64
		fmt.Fscanf(reader, "%d ", &q)
		fmt.Printf("%d\n", bin_search(0, piles-1, q, cum_worms))
	}
	// writer.Flush()
}

package main

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

func cum_range(cum_worms []int64, i int64) (int64, int64) {
	if i == 0 {
		return 1, cum_worms[i]
	}
	return cum_worms[i-1] + 1, cum_worms[i]
}

func bin_search(l, r, q int64, cum_worms []int64) int64 {
	if l > r {
		return -1
	}
	mid := l + (r-l)/2
	start, end := cum_range(cum_worms, mid)
	if q >= start && q <= end {
		// q is within [start, end]
		return mid + 1
	}
	if q > end {
		// q is after end
		return bin_search(mid+1, r, q, cum_worms)
	}
	// q is before start
	return bin_search(l, mid-1, q, cum_worms)
}

// Create cumulative array cum_worms {c0, ..., ci, ci+1, ci+3, ..., cn}
// where ci is the total number of worms stored in all piles from 1 to i
// inclusive.
// Let the worm label be 'w'.
// Do binary search for 'w' in cum_worms and find pile number
func main() {
	reader := bufio.NewReader(os.Stdin)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	var piles int64
	fmt.Fscanf(reader, "%d\n", &piles)
	worm_counts := make([]int64, piles)
	cum_worms := make([]int64, piles)
	var i int64
	for i = 0; i < piles; i++ {
		scanner.Scan()
		w, _ := strconv.Atoi(scanner.Text())
		worm_counts[i] = int64(w)
		cum_worms[i] = worm_counts[i]
		if i == 0 {
			continue
		}
		cum_worms[i] += cum_worms[i-1]
	}
	var queries int64
	fmt.Fscanf(reader, "%d\n", &queries)
	for i = 0; i < queries; i++ {
		scanner.Scan()
		q, _ := strconv.Atoi(scanner.Text())
		fmt.Fprintf(writer, "%d\n", bin_search(0, piles-1, int64(q), cum_worms))
	}
	writer.Flush()
}

package main

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

func cum_range(cum_worms []int64, i int64) (int64, int64) {
	if i == 0 {
		return 1, cum_worms[i]
	}
	return cum_worms[i-1] + 1, cum_worms[i]
}

func bin_search(l, r, q int64, cum_worms []int64) int64 {
	if l > r {
		return -1
	}
	mid := l + (r-l)/2
	start, end := cum_range(cum_worms, mid)
	if q >= start && q <= end {
		// q is within [start, end]
		return mid + 1
	}
	if q > end {
		// q is after end
		return bin_search(mid+1, r, q, cum_worms)
	}
	// q is before start
	return bin_search(l, mid-1, q, cum_worms)
}

// Create cumulative array cum_worms {c0, ..., ci, ci+1, ci+3, ..., cn}
// where ci is the total number of worms stored in all piles from 1 to i
// inclusive.
// Let the worm label be 'w'.
// Do binary search for 'w' in cum_worms and find pile number
func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var piles int64
	fmt.Fscanf(reader, "%d\n", &piles)
	worm_counts := make([]int64, piles)
	cum_worms := make([]int64, piles)
	var i int64
	for i = 0; i < piles; i++ {
		fmt.Fscanf(reader, "%d ", &worm_counts[i])
		cum_worms[i] = worm_counts[i]
		if i == 0 {
			continue
		}
		cum_worms[i] += cum_worms[i-1]
	}
	var queries_count int64
	fmt.Fscanf(reader, "%d\n", &queries_count)
	for i = 0; i < queries_count; i++ {
		var q int64
		fmt.Fscanf(reader, "%d ", &q)
		fmt.Fprintf(writer, "%d\n", bin_search(0, piles-1, q, cum_worms))
	}
	writer.Flush()
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}

	var m int
	fmt.Scanf("%d", &m)
	//fmt.Println("m=", m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		fmt.Println("a", i, "=", a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}
	var m int
	fmt.Scanf("%d", &m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}

	var m int
	fmt.Scanf("%d", &m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}

	var m int
	fmt.Scanf("%d", &m)
	//fmt.Println("m=", m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}

	var m int
	fmt.Scanf("%d", &m)
	fmt.Println("m=", m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}
	fmt.Scan("%c")
	var m int
	fmt.Scanf("%d\n", &m)
	//fmt.Println("m=", m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		fmt.Println("a", i, "=", a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}
	fmt.Scanln()
	var m int
	fmt.Scanln(&m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		fmt.Println("a", i, "=", a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}
	var m int
	fmt.Scanf("%d", &m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

import "fmt"

type PointW struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	aa := make([]PointW, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if i == 0 {
			aa[i] = PointW{1, a[i]}
		} else {
			aa[i] = PointW{aa[i-1].y + 1, aa[i-1].y + a[i]}
		}
	}
	var m int
	fmt.Scanf("%d", &m)
	fmt.Println("m=", m)
	for i := 0; i < m; i++ {
		var b int
		fmt.Scanf("%d", &b)
		fmt.Println(find(aa, b) + 1)
	}
}

func find(aa []PointW, b int) int {
	start := 0
	end := len(aa) - 1
	index := (start + end) / 2
	for {
		if start >= end {
			return index
		}
		if aa[index].x <= b && b <= aa[index].y {
			return index
		}
		if b > aa[index].y {
			start = index + 1
		}
		if b < aa[index].x {
			end = index - 1
		}
		index = (start + end) / 2
	}
}

package main

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

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

    indexn := make([]int, 1e6+1, 1e6+1)
    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    id := 1
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        for j := 0; j < a; j++ {
            indexn[id] = i+1
            id++
        }
    }

    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        bs.Scan()
        p, _ := strconv.Atoi(bs.Text())
        fmt.Println(indexn[p])
    }
}

package main

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func PrintInts(sep byte,ints []int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(sep)
	}
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n,m,x,y,j int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0;i<n;i++ {
		a[i] = ReadInt32()
	}
	fmt.Scan(&m)
	j = 0
	y = a[j]
	r := make([]int,m)
	for i:=0;i<m;i++ {
		q := ReadInt32()
		for ;y<q;{
			j++
			x =  y
			y += a[j]
		}
		for ;x>=q;{
			j--
			y =  x
			x -= a[j]
		}
		r[i] = j+1
	}

	PrintInts('\n',r)
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n,m,x,y,j int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0;i<n;i++ {
		a[i] = ReadInt32()
	}
	fmt.Scan(&m)
	j = 0
	y = a[j]
	r := make([]string,m)
	for i:=0;i<m;i++ {
		q := ReadInt32()
		for ;y<q;{
			j++
			x =  y
			y += a[j]
		}
		for ;x>=q;{
			j--
			y =  x
			x -= a[j]
		}
		r[i] = strconv.Itoa(j+1)
	}

	fmt.Println(strings.Join(r,"\n"))

}

package main

import (
	"fmt"
)

func main() {
	var n,m,x,y,j int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	j = 0
	y = a[j]
	r := make([]int,m)
	for i:=0;i<m;i++ {
		var q int
		fmt.Scan(&q)
		for ;y<q;{
			j++
			x =  y
			y += a[j]
		}
		for ;x>q;{
			j--
			y =  x
			x -= a[j]
		}
		r[i] = j+1
	}

	for _,i := range r {
		fmt.Println(i)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n,m,x,y,j int
	fmt.Scan(&n)
	a := make([]int,n)
	for i:=0;i<n;i++ {
		a[i] = ReadInt32()
	}
	fmt.Scan(&m)
	j = 0
	y = a[j]
	r := make([]string,m)
	for i:=0;i<m;i++ {
		q := ReadInt32()
		for ;y<q;{
			j++
			x =  y
			y += a[j]
		}
		for ;x>=q;{
			j--
			y =  x
			x -= a[j]
		}
		r[i] = strconv.Itoa(j+1)
	}

	fmt.Println(strings.Join(r,"\r\n"))

}

package main

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

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

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

type Pairs struct {
	l int
	r int
}

func main() {
	n := nextInt()

	ranges := make([]Pairs, n)

	curr := nextInt()
	ranges[0] = Pairs{1, curr}
	lasti := curr
	for i := 1; i < n; i++ {
		curr = nextInt()
		ranges[i] = Pairs{lasti + ranges[i-1].l, curr + ranges[i-1].r}
		lasti = curr
	}

	m := nextInt()
	var ll, rr, mid int
	for i := 0; i < m; i++ {
		q := nextInt()

		ll = 0
		rr = n
		for ll <= rr {
			mid = (ll + rr) / 2
			if ranges[mid].l <= q && q <= ranges[mid].r {
				fmt.Fprintln(out, m+1)
				break
			}
			if ranges[mid].r < q {
				ll = mid + 1
			} else {
				rr = mid - 1
			}
		}
	}
	out.Flush()
}

package main

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

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

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

type Pairs struct {
	l int
	r int
}

func main() {
	n := nextInt()

	ranges := make([]Pairs, n)

	curr := nextInt()
	ranges[0] = Pairs{1, curr}
	lasti := curr
	for i := 1; i < n; i++ {
		curr = nextInt()
		ranges[i] = Pairs{lasti + ranges[i-1].l, curr + ranges[i-1].r}
		lasti = curr
	}

	m := nextInt()
	var ll, rr, mid int
	for i := 0; i < m; i++ {
		q := nextInt()

		ll = 0
		rr = n
		for ll <= rr {
			mid = (ll + rr) / 2
			if ranges[mid].l <= q && q <= ranges[mid].r {
				fmt.Println(mid + 1)
				break
			}
			if ranges[mid].r < q {
				ll = mid + 1
			} else {
				rr = mid - 1
			}
		}
	}
}

package main

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

type Pairs struct {
	l int
	r int
}

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

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

func main() {
	defer writer.Flush()
	var n, m int

	n = readInt()
	ranges := make([]Pairs, n)

	var curr, lasti int
	curr = readInt()
	ranges[0] = Pairs{1, curr}
	lasti = curr
	for i := 1; i < n; i++ {
		curr = readInt()
		ranges[i] = Pairs{lasti + ranges[i-1].l, curr + ranges[i-1].r}
		lasti = curr
	}

	m = readInt()
	var ll, rr, mid, q int
	for i := 0; i < m; i++ {
		q = readInt()

		ll = 0
		rr = n
		for ll <= rr {
			mid = (ll + rr) / 2
			if ranges[mid].l <= q && q <= ranges[mid].r {
				fmt.Fprintln(writer, m+1)
				break
			}
			if ranges[mid].r < q {
				ll = mid + 1
			} else {
				rr = mid - 1
			}
		}
	}
}


There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in the railway carriage so that:  no student-programmer is sitting next to the student-programmer;  and no student-athlete is sitting next to the student-athlete. In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).

The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with length $$$n$$$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.

Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.

NoteIn the first example you can put all student, for example, in the following way: *.AB*In the second example you can put four students, for example, in the following way: *BAB*BIn the third example you can put seven students, for example, in the following way: B*ABAB**A*BThe letter A means a student-programmer, and the letter B — student-athlete.

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func next() []byte {
	in.Scan()
	return in.Bytes()
}

func main() {
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 262144), 262144)
	_, a, b, r := nextInt(), nextInt(), nextInt(), 0
	s := bytes.FieldsFunc(next(), func(r rune) bool { return r == '*' })
	for _, s := range s {
		if a < b {
			a, b = b, a
		}
		xa, xb := (len(s)+1)/2, len(s)/2
		if a < xa {
			r += a
			a = 0
		} else {
			r += xa
			a -= xa
		}
		if b < xb {
			r += b
			b = 0
		} else {
			r += xb
			b -= xb
		}
		if a == 0 && b == 0 {
			break
		}
	}
	fmt.Println(r)
}

package main

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

type caseInput struct {
	a, p  uint32
	seats string
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	_ = uint32(readInt64(scanner))

	a := uint32(readInt64(scanner))
	p := uint32(readInt64(scanner))
	seats := readString(scanner)

	return caseInput{a, p, seats}
}

type caseOutput struct {
	seated uint32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", out.seated)
}

type Uint32Slice []uint32

func (p Uint32Slice) Len() int           { return len(p) }
func (p Uint32Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Uint32Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func solveCase(in caseInput) caseOutput {
	freeZoneSizes := make([]uint32, 0, 0)

	firstFreeSeat := -1
	for i, c := range []rune(in.seats) {
		if c == '*' {
			if firstFreeSeat >= 0 {
				freeZoneSizes = append(freeZoneSizes, uint32(i-firstFreeSeat))
				firstFreeSeat = -1
			}
		} else if c == '.' {
			if firstFreeSeat == -1 {
				firstFreeSeat = i
			}
		}
	}
	if firstFreeSeat != -1 {
		freeZoneSizes = append(freeZoneSizes, uint32(len(in.seats)-firstFreeSeat))
	}

	sort.Sort(Uint32Slice(freeZoneSizes))

	seated := uint32(0)
	a, p := in.a, in.p
	for len(freeZoneSizes) > 0 && a+p > 0 {
		freeZone := freeZoneSizes[0]
		freeZoneSizes = freeZoneSizes[1:]

		bigger := (freeZone + 1) / 2
		smaller := freeZone / 2

		seatedA := uint32(0)
		seatedP := uint32(0)
		if a > p {
			seatedA = min_u32(a, bigger)
			seatedP = min_u32(p, smaller)
		} else {
			seatedA = min_u32(a, smaller)
			seatedP = min_u32(p, bigger)
		}

		seated += seatedA
		seated += seatedP
		a -= seatedA
		p -= seatedP
	}

	return caseOutput{seated}
}

func solveSequential(scanner *bufio.Scanner, writer *bufio.Writer) {
	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte,0,1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	solveSequential(scanner, writer)
}

func readString(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	return sc.Text()
}

func readInt64(sc *bufio.Scanner) int64 {
	if !sc.Scan() {
		panic("failed to scan next token")
	}
	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

func min_u32(a, b uint32) uint32 {
	if a < b {
		return a
	}
	return b
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = false

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

	in := gsli(reader)

	a := in[1]
	b := in[2]

	seats := gsls(reader)[0]
	seated := 0
	lastSeated := 0

	if a > b {
		lastSeated = 1
	} else {
		lastSeated = 0
	}

	for _, c := range seats {
		if string(c) == "*" {
			if a > b {
				lastSeated = 1
			} else {
				lastSeated = 0
			}
			continue
		}
		if lastSeated == 0 {
			lastSeated = 1
			if b > 0 {
				b--
				seated++
				dbg("Seated b")
			}

		} else if lastSeated == 1 {
			lastSeated = 0
			if a > 0 {
				a--
				seated++
				dbg("Seated a")
			}
		}
	}

	fmt.Println(seated)

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

package main

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

type caseInput struct {
	a, p  uint32
	seats string
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	_ = uint32(readInt64(scanner))

	a := uint32(readInt64(scanner))
	p := uint32(readInt64(scanner))
	seats := readString(scanner)

	return caseInput{a, p, seats}
}

type caseOutput struct {
	seated uint32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", out.seated)
}

type Uint32Slice []uint32

func (p Uint32Slice) Len() int           { return len(p) }
func (p Uint32Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Uint32Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func solveCase(in caseInput) caseOutput {
	freeZoneSizes := make([]uint32, 0, 0)

	firstFreeSeat := -1
	for i, c := range []rune(in.seats) {
		if c == '*' {
			if firstFreeSeat >= 0 {
				freeZoneSizes = append(freeZoneSizes, uint32(i-firstFreeSeat))
				firstFreeSeat = -1
			}
		} else if c == '.' {
			if firstFreeSeat == -1 {
				firstFreeSeat = i
			}
		}
	}
	if firstFreeSeat != -1 {
		freeZoneSizes = append(freeZoneSizes, uint32(len(in.seats)-firstFreeSeat))
	}

	sort.Sort(Uint32Slice(freeZoneSizes))

	seated := uint32(0)
	a, p := in.a, in.p
	for len(freeZoneSizes) > 0 && a+p > 0 {
		freeZone := freeZoneSizes[0]
		freeZoneSizes = freeZoneSizes[1:]

		bigger := (freeZone + 1) / 2
		smaller := freeZone / 2

		seatedA := uint32(0)
		seatedP := uint32(0)
		if a > p {
			seatedA = min_u32(a, bigger)
			seatedP = min_u32(p, smaller)
		} else {
			seatedA = min_u32(a, smaller)
			seatedP = min_u32(p, bigger)
		}

		seated += seatedA
		seated += seatedP
		a -= seatedA
		p -= seatedP
	}

	return caseOutput{seated}
}

func solveSequential(scanner *bufio.Scanner, writer *bufio.Writer) {
	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	solveSequential(scanner, writer)
}

func readString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func readInt64(sc *bufio.Scanner) int64 {
	sc.Scan()
	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

func min_u32(a, b uint32) uint32 {
	if a < b {
		return a
	}
	return b
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = false

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

	in := gsli(reader)

	a := in[1]
	b := in[2]

	seats := gsls(reader)[0]
	seated := 0
	lastSeated := 0

	if a > b {
		lastSeated = 1
	} else {
		lastSeated = 0
	}

	for _, c := range seats {
		if string(c) == "*" {
			if a > b {
				lastSeated = 1
			} else {
				lastSeated = 0
			}
			continue
		}
		if lastSeated == 0 && b > 0 {
			b--
			seated++
			lastSeated = 1
			dbg("Seated b")
		} else if lastSeated == 1 && a > 0 {
			a--
			seated++
			lastSeated = 0
			dbg("Seated a")

		}
	}

	fmt.Println(seated)

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = false

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

	in := gsli(reader)

	a := in[1]
	b := in[2]

	seats := gsls(reader)[0]
	seated := 0
	lastSeated := 0

	if a > b {
		lastSeated = 1
	} else {
		lastSeated = 0
	}

	for _, c := range seats {
		if string(c) == "*" {
			if a > b {
				lastSeated = 1
			} else {
				lastSeated = 0
			}
			continue
		}
		if lastSeated == 0 {
			lastSeated = 1
			if b > 0 {
				b--
				seated++
				dbg("Seated b")
			}

		} else if lastSeated == 1 && a > 0 {
			seated++
			lastSeated = 0
			if a > 0 {
				a--

				dbg("Seated a")
			}
		}
	}

	fmt.Println(seated)

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}


You are given an array $$$a$$$ of length $$$n$$$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.

Output the length of the shortest non-empty subsequence of $$$a$$$ product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

NoteIn the first sample, you can choose a subsequence $$$[1]$$$.In the second sample, you can choose a subsequence $$$[6, 6]$$$.In the third sample, you can choose a subsequence $$$[6, 15, 10]$$$.In the fourth sample, there is no such subsequence.

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

type Graph struct {
	n     int
	m     int
	edges int
	fst   []int
	nxt   []int
	end   []int
}

func (g *Graph) Add(a, b int) {
	g.nxt[g.edges] = g.fst[a]
	g.fst[a] = g.edges
	g.end[g.edges] = b
	g.edges++
}

func (g *Graph) Adjacent(a int, fn func(b int)) {
	for u := g.fst[a]; u != -1; u = g.nxt[u] {
		fn(g.end[u])
	}
}

func NewGraph(n, m int) *Graph {
	g := &Graph{n, m, 0, make([]int, n), make([]int, m), make([]int, m)}
	for i := 0; i < n; i++ {
		g.fst[i] = -1
	}
	return g
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 10010)

	n := NextInt()

	m := 1000001
	prime := make([]int, m)
	smallPrimes := make([]int, 0, 1000)
	for j := 2; j < m; j++ {
		if prime[j] == 0 {
			prime[j] = j
			if j <= 1000 {
				smallPrimes = append(smallPrimes, j)
				for i := j * j; i < m; i += j {
					if prime[i] == 0 {
						prime[i] = j
					}
				}
			}
		}
	}

	// stderr(np)

	edges := make([][2]int, 0, 2 * n)
	vertices := make([]int, 0, 2 * n)
	for i := 0; i < n; i++ {
		ai := NextInt()
		firstPrime := prime[ai]
		cnt0 := 0
		for firstPrime != 0 && ai%firstPrime == 0 {
			ai /= firstPrime
			cnt0 ^= 1
		}
		secondPrime := prime[ai]
		cnt1 := 0
		for secondPrime != 0 && ai%secondPrime == 0 {
			ai /= secondPrime
			cnt1 ^= 1
		}

		if cnt0 == 0 && cnt1 == 0 {
			fmt.Fprintln(out, 1)
			return
		}

		if cnt0 == 0 {
			cnt0, cnt1 = cnt1, cnt0
			firstPrime, secondPrime = secondPrime, firstPrime
		}

		if cnt1 == 0 {
			vertices = append(vertices, 1, firstPrime)
			edges = append(edges, [2]int{1, firstPrime})
			edges = append(edges, [2]int{firstPrime, 1})
		} else {
			vertices = append(vertices, firstPrime, secondPrime)
			edges = append(edges, [2]int{firstPrime, secondPrime})
			edges = append(edges, [2]int{secondPrime, firstPrime})
		}
	}

	sort.Ints(vertices)
	vertices = vertices[:unique(vertices)]

	sort.Slice(edges, func(i, j int) bool {
		return edges[i][0] < edges[j][0] || edges[i][0] == edges[j][0] && edges[i][1] < edges[j][1]
	})

	for i := 1; i < len(edges); i++ {
		if edges[i-1][0] == edges[i][0] && edges[i-1][1] == edges[i][1] {
			fmt.Fprintln(out, 2)
			return
		}
	}

	g := NewGraph(m, len(edges))
	for i := 0; i < len(edges); i++ {
		g.Add(edges[i][0], edges[i][1])
	}

	smallPrimes = append(smallPrimes, 1)
	INF := n + 1
	d := make([]int, m)
	parent := make([]int, m)
	q := make([]int, len(vertices))
	res := INF
	for _, start := range smallPrimes {
		for _, v := range vertices {
			d[v] = INF
			parent[v] = 0
		}
		qh := 0
		qt := 0
		q[qt] = start
		d[start] = 0
		qt++

		for qh < qt {
			v := q[qh]
			if d[v] > res / 2 {
				break
			}
			qh++
			g.Adjacent(v, func(to int) {
				if parent[v] == to {
					return
				}
				if d[to] != INF {
					res = min(res, d[v] + d[to] + 1)
				}
				if d[to] == INF {
					d[to] = d[v] + 1
					parent[to] = v
					q[qt] = to
					qt++
				}
			})
		}
	}

	if res < INF {
		fmt.Fprintln(out, res)
	} else {
		fmt.Fprintln(out, -1)
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

type Graph struct {
	n     int
	m     int
	edges int
	fst   []int
	nxt   []int
	end   []int
}

func (g *Graph) Add(a, b int) {
	g.nxt[g.edges] = g.fst[a]
	g.fst[a] = g.edges
	g.end[g.edges] = b
	g.edges++
}

func (g *Graph) Adjacent(a int, fn func(b int)) {
	for u := g.fst[a]; u != -1; u = g.nxt[u] {
		fn(g.end[u])
	}
}

func NewGraph(n, m int) *Graph {
	g := &Graph{n, m, 0, make([]int, n), make([]int, m), make([]int, m)}
	for i := 0; i < n; i++ {
		g.fst[i] = -1
	}
	return g
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 10010)

	n := NextInt()

	m := 1000001
	prime := make([]int, m)
	smallPrimes := make([]int, 0, 1000)
	for j := 2; j < m; j++ {
		if prime[j] == 0 {
			prime[j] = j
			if j <= 1000 {
				smallPrimes = append(smallPrimes, j)
				for i := j * j; i < m; i += j {
					if prime[i] == 0 {
						prime[i] = j
					}
				}
			}
		}
	}

	// stderr(np)

	edges := make([][2]int, 0, 2 * n)
	vertices := make([]int, 0, 2 * n)
	for i := 0; i < n; i++ {
		ai := NextInt()
		firstPrime := prime[ai]
		cnt0 := 0
		for firstPrime != 0 && ai%firstPrime == 0 {
			ai /= firstPrime
			cnt0 ^= 1
		}
		secondPrime := prime[ai]
		cnt1 := 0
		for secondPrime != 0 && ai%secondPrime == 0 {
			ai /= secondPrime
			cnt1 ^= 1
		}

		if cnt0 == 0 && cnt1 == 0 {
			fmt.Fprintln(out, 1)
			return
		}

		if cnt0 == 0 {
			cnt0, cnt1 = cnt1, cnt0
			firstPrime, secondPrime = secondPrime, firstPrime
		}

		if cnt1 == 0 {
			vertices = append(vertices, 1, firstPrime)
			edges = append(edges, [2]int{1, firstPrime})
			edges = append(edges, [2]int{firstPrime, 1})
		} else {
			vertices = append(vertices, firstPrime, secondPrime)
			edges = append(edges, [2]int{firstPrime, secondPrime})
			edges = append(edges, [2]int{secondPrime, firstPrime})
		}
	}

	sort.Ints(vertices)
	vertices = vertices[:unique(vertices)]

	sort.Slice(edges, func(i, j int) bool {
		return edges[i][0] < edges[j][0] || edges[i][0] == edges[j][0] && edges[i][1] < edges[j][1]
	})

	for i := 1; i < len(edges); i++ {
		if edges[i-1][0] == edges[i][0] && edges[i-1][1] == edges[i][1] {
			fmt.Fprintln(out, 2)
			return
		}
	}

	g := NewGraph(m, len(edges))
	for i := 0; i < len(edges); i++ {
		g.Add(edges[i][0], edges[i][1])
	}

	smallPrimes = append(smallPrimes, 1)
	INF := n + 1
	d := make([]int, m)
	parent := make([]int, m)
	q := make([]int, len(vertices))
	res := INF
	for _, start := range smallPrimes {
		for _, v := range vertices {
			d[v] = INF
			parent[v] = 0
		}
		qh := 0
		qt := 0
		q[qt] = start
		d[start] = 0
		qt++
		// smallestFound := false

		for qh < qt {
			v := q[qh]
			qh++
			g.Adjacent(v, func(to int) {
				if parent[v] == to {
					return
				}
				if d[to] != INF {
					// smallestFound = true
					res = min(res, d[v] + d[to] + 1)
				}
				if d[to] == INF {
					d[to] = d[v] + 1
					parent[to] = v
					q[qt] = to
					qt++
				}
			})
		}
	}

	if res < INF {
		fmt.Fprintln(out, res)
	} else {
		fmt.Fprintln(out, -1)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	const mx int = 1e6
	lp := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lp[i] == 0 {
			for j := i; j <= mx; j += i {
				if lp[j] == 0 {
					lp[j] = i
				}
			}
		}
	}

	g := make([][]int, mx)
	var n, v int
	in := bufio.NewReader(os.Stdin)
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		ps := []int{}
		for v > 1 {
			p := lp[v]
			c := 1
			for v /= p; lp[v] == p; v /= p {
				c++
			}
			if c&1 == 1 {
				ps = append(ps, p)
			}
		}
		if len(ps) == 0 {
			Print(1)
			return
		}
		if len(ps) == 1 {
			ps = append(ps, 1)
		}
		v, w := ps[0], ps[1]
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	ans := int(1e9)
	d := make([]int, mx)
	for i := range d {
		d[i] = -1
	}
	type pair struct{ v, fa int }
	var p pair
	for st := 1; st < 1000; st++ {
		vs := []int{st}
		d[st] = 0
		q := []pair{{st, -1}}
		for len(q) > 0 {
			p, q = q[0], q[1:]
			v := p.v
			for _, w := range g[v] {
				if d[w] == -1 {
					d[w] = d[v] + 1
					q = append(q, pair{w, v})
					vs = append(vs, w)
				} else if w != p.fa {
					if l := d[w] + d[v] + 1; l < ans {
						ans = l
					}
				}
			}
		}
		for _, v := range vs {
			d[v] = -1
		}
	}
	if ans == 1e9 {
		ans = -1
	}
	Print(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)

	const mx, inf int = 1e6, 1e9
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	g := make([][]int, mx)
	var n, v int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		ps := make([]int, 0, 2)
		for v > 1 {
			p := lpf[v]
			cnt := 1
			for v /= p; lpf[v] == p; v /= p {
				cnt++
			}
			if cnt&1 == 1 {
				ps = append(ps, p)
			}
		}
		if len(ps) == 0 {
			Fprint(_w, 1)
			return
		}
		if len(ps) == 1 {
			ps = append(ps, 1)
		}
		v, w := ps[0], ps[1]
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	ans := inf
	dist := make([]int, mx)
	for i := range dist {
		dist[i] = -1
	}
	type pair struct{ v, fa int }
	var p pair
	for st := 1; st < 1000; st++ {
		vs := []int{st}
		dist[st] = 0
		q := []pair{{st, -1}}
		for len(q) > 0 {
			p, q = q[0], q[1:]
			v, fa := p.v, p.fa
			for _, w := range g[v] {
				if dist[w] == -1 {
					dist[w] = dist[v] + 1
					q = append(q, pair{w, v})
					vs = append(vs, w)
				} else if w != fa {
					if l := dist[w] + dist[v] + 1; l < ans {
						ans = l
					}
				}
			}
		}
		for _, v := range vs {
			dist[v] = -1
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)

	const mx, inf int = 1e6, 1e9
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	g := make([][]int, mx)
	var n, v int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		ps := make([]int, 0, 2)
		for v > 1 {
			p := lpf[v]
			cnt := 1
			for v /= p; lpf[v] == p; v /= p {
				cnt++
			}
			if cnt&1 == 1 {
				ps = append(ps, p)
			}
		}
		if len(ps) == 0 {
			Fprint(_w, 1)
			return
		}
		if len(ps) == 1 {
			ps = append(ps, 1)
		}
		v, w := ps[0], ps[1]
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	ans := inf
	dist := make([]int, mx)
	for i := range dist {
		dist[i] = -1
	}
	fa := make([]int, mx)
	for st := 1; st < 1000; st++ {
		vs := []int{st}
		dist[st] = 0
		fa[st] = -1
		q := []int{st}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dist[w] == -1 {
					dist[w] = dist[v] + 1
					fa[w] = v
					q = append(q, w)
					vs = append(vs, w)
				} else if w != fa[v] {
					if l := dist[w] + dist[v] + 1; l < ans {
						ans = l
					}
				}
			}
		}
		for _, v := range vs {
			dist[v] = -1
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325E(_r io.Reader, _w io.Writer) {
	const mx, inf int = 1e6, 1e9
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	g := make([][]int, mx)
	var n, v int
	in := bufio.NewReader(_r)
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		ps := make([]int, 0, 2)
		for v > 1 {
			p := lpf[v]
			cnt := 1
			for v /= p; lpf[v] == p; v /= p {
				cnt++
			}
			if cnt&1 == 1 {
				ps = append(ps, p)
			}
		}
		if len(ps) == 0 {
			Fprint(_w, 1)
			return
		}
		if len(ps) == 1 {
			ps = append(ps, 1)
		}
		v, w := ps[0], ps[1]
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	ans := inf
	dist := make([]int, mx)
	for i := range dist {
		dist[i] = -1
	}
	type pair struct{ v, fa int }
	var p pair
	for st := 1; st < 1000; st++ {
		vs := []int{st}
		dist[st] = 0
		q := []pair{{st, -1}}
	o:
		for len(q) > 0 {
			p, q = q[0], q[1:]
			v, fa := p.v, p.fa
			for _, w := range g[v] {
				if dist[w] == -1 {
					dist[w] = dist[v] + 1
					q = append(q, pair{w, v})
					vs = append(vs, w)
				} else if w != fa {
					if l := dist[w] + dist[v] + 1; l < ans {
						ans = l
					}
					break o
				}
			}
		}
		for _, v := range vs {
			dist[v] = -1
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(_w, ans)
}

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

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

type Graph struct {
	n     int
	m     int
	edges int
	fst   []int
	nxt   []int
	end   []int
}

func (g *Graph) Add(a, b int) {
	g.nxt[g.edges] = g.fst[a]
	g.fst[a] = g.edges
	g.end[g.edges] = b
	g.edges++
}

func (g *Graph) Adjacent(a int, fn func(b int)) {
	for u := g.fst[a]; u != -1; u = g.nxt[u] {
		fn(g.end[u])
	}
}

func NewGraph(n, m int) *Graph {
	g := &Graph{n, m, 0, make([]int, n), make([]int, m), make([]int, m)}
	for i := 0; i < n; i++ {
		g.fst[i] = -1
	}
	return g
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 10010)

	n := NextInt()

	m := 1000001
	prime := make([]int, m)
	smallPrimes := make([]int, 0, 1000)
	for j := 2; j < m; j++ {
		if prime[j] == 0 {
			prime[j] = j
			if j <= 1000 {
				smallPrimes = append(smallPrimes, j)
				for i := j * j; i < m; i += j {
					if prime[i] == 0 {
						prime[i] = j
					}
				}
			}
		}
	}

	// stderr(np)

	edges := make([][2]int, 0, 2 * n)
	vertices := make([]int, 0, 2 * n)
	for i := 0; i < n; i++ {
		ai := NextInt()
		firstPrime := prime[ai]
		cnt0 := 0
		for firstPrime != 0 && ai%firstPrime == 0 {
			ai /= firstPrime
			cnt0 ^= 1
		}
		secondPrime := prime[ai]
		cnt1 := 0
		for secondPrime != 0 && ai%secondPrime == 0 {
			ai /= secondPrime
			cnt1 ^= 1
		}

		if cnt0 == 0 && cnt1 == 0 {
			fmt.Fprintln(out, 1)
			return
		}

		if cnt0 == 0 {
			cnt0, cnt1 = cnt1, cnt0
			firstPrime, secondPrime = secondPrime, firstPrime
		}

		if cnt1 == 0 {
			vertices = append(vertices, 1, firstPrime)
			edges = append(edges, [2]int{1, firstPrime})
			edges = append(edges, [2]int{firstPrime, 1})
		} else {
			vertices = append(vertices, firstPrime, secondPrime)
			edges = append(edges, [2]int{firstPrime, secondPrime})
			edges = append(edges, [2]int{secondPrime, firstPrime})
		}
	}

	sort.Ints(vertices)
	vertices = vertices[:unique(vertices)]

	sort.Slice(edges, func(i, j int) bool {
		return edges[i][0] < edges[j][0] || edges[i][0] == edges[j][0] && edges[i][1] < edges[j][1]
	})

	for i := 1; i < len(edges); i++ {
		if edges[i-1][0] == edges[i][0] && edges[i-1][1] == edges[i][1] {
			fmt.Fprintln(out, 2)
			return
		}
	}

	g := NewGraph(m, len(edges))
	for i := 0; i < len(edges); i++ {
		g.Add(edges[i][0], edges[i][1])
	}

	smallPrimes = append(smallPrimes, 1)
	INF := n + 1
	d := make([]int, m)
	parent := make([]int, m)
	q := make([]int, len(vertices))
	res := INF
	for _, start := range smallPrimes {
		for _, v := range vertices {
			d[v] = INF
			parent[v] = 0
		}
		qh := 0
		qt := 0
		q[qt] = start
		d[start] = 0
		qt++
		smallestFound := false

		for !smallestFound && qh < qt {
			v := q[qh]
			qh++
			g.Adjacent(v, func(to int) {
				if parent[v] == to {
					return
				}
				if d[to] != INF && !smallestFound {
					smallestFound = true
					res = min(res, d[v] + d[to] + 1)
				}
				if d[to] == INF {
					d[to] = d[v] + 1
					parent[to] = v
					q[qt] = to
					qt++
				}
			})
		}
	}

	if res < INF {
		fmt.Fprintln(out, res)
	} else {
		fmt.Fprintln(out, -1)
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

type Graph struct {
	n     int
	m     int
	edges int
	fst   []int
	nxt   []int
	end   []int
}

func (g *Graph) Add(a, b int) {
	g.nxt[g.edges] = g.fst[a]
	g.fst[a] = g.edges
	g.end[g.edges] = b
	g.edges++
}

func (g *Graph) Adjacent(a int, fn func(b int)) {
	for u := g.fst[a]; u != -1; u = g.nxt[u] {
		fn(g.end[u])
	}
}

func NewGraph(n, m int) *Graph {
	g := &Graph{n, m, 0, make([]int, n), make([]int, m), make([]int, m)}
	for i := 0; i < n; i++ {
		g.fst[i] = -1
	}
	return g
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 10010)

	n := NextInt()

	m := 1000001
	prime := make([]int, m)
	smallPrimes := make([]int, 0, 1000)
	for j := 2; j < m; j++ {
		if prime[j] == 0 {
			prime[j] = j
			if j <= 1000 {
				smallPrimes = append(smallPrimes, j)
				for i := j * j; i < m; i += j {
					if prime[i] == 0 {
						prime[i] = j
					}
				}
			}
		}
	}

	// stderr(np)

	edges := make([][2]int, 0, 2 * n)
	vertices := make([]int, 0, 2 * n)
	for i := 0; i < n; i++ {
		ai := NextInt()
		firstPrime := prime[ai]
		cnt0 := 0
		for firstPrime != 0 && ai%firstPrime == 0 {
			ai /= firstPrime
			cnt0 ^= 1
		}
		secondPrime := prime[ai]
		cnt1 := 0
		for secondPrime != 0 && ai%secondPrime == 0 {
			ai /= secondPrime
			cnt1 ^= 1
		}

		if cnt0 == 0 && cnt1 == 0 {
			fmt.Fprintln(out, 1)
			return
		}

		if cnt1 == 0 {
			vertices = append(vertices, 1, firstPrime)
			edges = append(edges, [2]int{1, firstPrime})
			edges = append(edges, [2]int{firstPrime, 1})
		} else {
			vertices = append(vertices, firstPrime, secondPrime)
			edges = append(edges, [2]int{firstPrime, secondPrime})
			edges = append(edges, [2]int{secondPrime, firstPrime})
		}
	}

	sort.Ints(vertices)
	vertices = vertices[:unique(vertices)]

	sort.Slice(edges, func(i, j int) bool {
		return edges[i][0] < edges[j][0] || edges[i][0] == edges[j][0] && edges[i][1] < edges[j][1]
	})

	for i := 1; i < len(edges); i++ {
		if edges[i-1][0] == edges[i][0] && edges[i-1][1] == edges[i][1] {
			fmt.Fprintln(out, 2)
			return
		}
	}

	g := NewGraph(m, len(edges))
	for i := 0; i < len(edges); i++ {
		g.Add(edges[i][0], edges[i][1])
	}

	smallPrimes = append(smallPrimes, 1)
	INF := n + 1
	d := make([]int, m)
	parent := make([]int, m)
	q := make([]int, len(vertices))
	res := INF
	for _, start := range smallPrimes {
		for _, v := range vertices {
			d[v] = INF
			parent[v] = 0
		}
		qh := 0
		qt := 0
		q[qt] = start
		d[start] = 0
		qt++
		smallestFound := false

		for !smallestFound && qh < qt {
			v := q[qh]
			qh++
			g.Adjacent(v, func(to int) {
				if d[to] != INF && parent[v] != to && !smallestFound {
					smallestFound = true
					res = min(res, d[v] + d[to] + 1)
				}
				if d[to] == INF {
					d[to] = d[v] + 1
					parent[to] = v
					q[qt] = to
					qt++
				}
			})
		}
	}

	if res < INF {
		fmt.Fprintln(out, res)
	} else {
		fmt.Fprintln(out, -1)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)

	const mx, inf int = 1e6, 1e9
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	g := make([][]int, mx)
	var n, v int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		ps := make([]int, 0, 2)
		for v > 1 {
			p := lpf[v]
			cnt := 1
			for v /= p; lpf[v] == p; v /= p {
				cnt++
			}
			if cnt&1 == 1 {
				ps = append(ps, p)
			}
		}
		if len(ps) == 0 {
			Fprint(_w, 1)
			return
		}
		if len(ps) == 1 {
			ps = append(ps, 1)
		}
		v, w := ps[0], ps[1]
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	ans := inf
	dist := make([]int, mx)
	for i := range dist {
		dist[i] = -1
	}
	fa := make([]int, mx)
	for st := 2; st < 1000; st++ {
		vs := []int{st}
		dist[st] = 0
		fa[st] = -1
		q := []int{st}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dist[w] == -1 {
					dist[w] = dist[v] + 1
					fa[w] = v
					q = append(q, w)
					vs = append(vs, w)
				} else if w != fa[v] {
					if l := dist[w] + dist[v] + 1; l < ans {
						ans = l
					}
				}
			}
		}
		for _, v := range vs {
			dist[v] = -1
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(_w, ans)
}

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