In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.

The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin.

Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.

package main
import (
	"fmt"
)
func main() {
	var n,i,j int
	fmt.Scan(&n)
	fmt.Print(n," ")
	i=n-1
	j=n
	for ;i>0;i-- {
		if j%i==0 {
			fmt.Print(i," ")
			j=i
		}
	}
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    prev := n
    for i := n; i >= 1; i-- {
        if prev%i == 0 {
            writer.WriteString(strconv.Itoa(i))
            if i == 1 { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
            prev = i
        }
    }
    writer.Flush()
}

// Codeforces 58 B training, done
package main

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

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

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

var n int

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
}

func nextDiv() {
	for i := n-1; i>1; i-- {
		if n%i==0 {
			n = i
			return
		}
	}
	n = 1
}

func solve() {
	for n>1 {
		fmt.Printf("%d ", n)
		nextDiv()
	}
}

func printRes() {
	fmt.Print (" 1\n")
}

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


An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one — to the 1-st and the 3-rd ones, the 3-rd one — only to the 2-nd one. The transitions are possible only between the adjacent sections.The spacecraft team consists of n aliens. Each of them is given a rank — an integer from 1 to n. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section a to section b only if it is senior in rank to all aliens who are in the segments a and b (besides, the segments a and b are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship.Alien A is senior in rank to alien B, if the number indicating rank A, is more than the corresponding number for B.At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task.Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo m.

The first line contains two space-separated integers: n and m (1 ≤ n, m ≤ 109) — the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.

Print a single number — the answer to the problem modulo m.

NoteIn the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.To briefly describe the movements in the second sample we will use value , which would correspond to an alien with rank i moving from the segment in which it is at the moment, to the segment number j. Using these values, we will describe the movements between the segments in the second sample: , , , , , , , , , , , , , , , , , , , , , , , , , ; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2.

package main

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

func main(){
	var n, m int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	m, _ = strconv.ParseInt(r.Text(), 0, 64)
	var a int64 = 3
	var b int64 = 1
	for n > 0 {
		if n%2 != 0 {
			b = (b*a)%m
		}
		a = (a*a)%m
		n = n/2
	}
	w.WriteString(strconv.FormatInt((b-1+m)%m, 10)+"\n")
	w.Flush()
}

// 226A
package main

import (
	"fmt"
)

func pow(x, n, mod int64) int64 {
	var a, t int64
	a = 1
	t = x
	for n != 0 {
		if n&1 == 1 {
			a = (a * t) % mod
		}
		t = (t * t) % mod
		n >>= 1
	}
	return int64(a)
}
func main() {
	var a, x, c int64
	fmt.Scan(&a, &x)
	c = pow(3, a, x)
	fmt.Println((c - 1 + x) % x)
}

package main

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

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

var memo map[int64]int64

func pow3(n, m int64) int64 {
	x, present := memo[n]
	if present {
		return x
	}
	x = (pow3(n/2, m) * pow3(n-n/2, m)) % m
	memo[n] = x
	return x
}

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

	n := int64(scanInt(scanner))
	m := int64(scanInt(scanner))
	memo = map[int64]int64{ 0: 1%m, 1: 3%m }
	x := pow3(n, m) - 1
	if x == -1 {
		x = m-1
	}
	writer.WriteString(fmt.Sprintf("%d\n", x))
}

package main

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

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

var memo map[int]int

func pow3(n, m int) int {
	x, present := memo[n]
	if present {
		return x
	}
	x = (pow3(n/2, m) * pow3(n-n/2, m)) % m
	memo[n] = x
	return x
}

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

	n := scanInt(scanner)
	m := scanInt(scanner)
	memo = map[int]int{ 0: 1%m, 1: 3%m }
	x := pow3(n, m) - 1
	if x == -1 {
		x = m-1
	}
	writer.WriteString(fmt.Sprintf("%d\n", x))
}

package main

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

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

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

	n := int64(scanInt(scanner))
	m := int64(scanInt(scanner))
	x := int64(1)
	for i := int64(1); i <= n; i++ {
		x *= 3
		if x >= m {
			x = ((x%m)*(n/i))%m
			for j := n%i; j != 0; j-- {
				x *= 3
				if x >= m {
					x %= m
				}
			}
			break
		}
	}
	x--
	if x == -1 {
		x = m-1
	}
	writer.WriteString(fmt.Sprintf("%d\n", x))
}


This version of the problem differs from the next one only in the constraint on $$$n$$$.Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds:   Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$.  Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$\lfloor \frac{x}{z} \rfloor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number) — the length of the strip and the modulo.

Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$.

NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$.Therefore, there are five ways in total.

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	//fmt.Fscan(in, &test)
	test = 1
	for i := 0; i < test; i++ {
		solve()
	}

}
func solve() {
	var n, m int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)
	var dp = make([]int64, n+1)
	dp[1] = 1
	var currentWays int64 = 1
	for i := 2; i <= int(n); i++ {
		dp[i] = currentWays
		for j := 1; j*j <= i; j++ {
			//smaller ocurrance
			var numberOfOccurance = int64(i/j - i/(j+1))
			dp[i] += (dp[j] * numberOfOccurance) % m
			dp[i] %= m
			if j != i/j && j > 1 {
				dp[i] += dp[i/j]
				dp[i] %= m
			}
		}
		currentWays += dp[i]
		currentWays %= m
	}
	fmt.Println(dp[n])
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

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

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var n int
	var m int64
	fmt.Fscan(r, &n, &m)
	w1 := do(n, m)
	fmt.Fprintln(w, w1)
}

/*x/2 x/3      ... x/n/2 ... x/n
1 2,3 3,4,5    ... n/2   ... n
2 4,5 6,7,8    ... n
3 6,7 9,10,11  ...
4 8,9 12,13,14 ...
. ...
n+n/2+n/3+...+n/n-1=n(1+1/2+1/3+...)=nlogn
*/

func do(n int, m int64) int64 {
	a := make([]int64, n+2)
	a[n] = 1
	for i := n - 1; i >= 1; i-- {
		a[i] = a[i+1]
		for j := 2; j*i <= n; j++ {
			a[i] = (a[i] + a[j*i] - a[min(n+1, j*i+j)] + m) % m
		}
		a[i] = (a[i] + a[i+1]) % m
	}
	return (a[1] - a[2] + m) % m
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, m int64
	fmt.Fscan(in, &n, &m)
	f := make([]int64, n+5)
	f[1] = 1
	pre := make([]int64, n+5)
	pre[1] = 1
	f[2] = 2
	f[3] = 5
	pre[2] = f[1] + f[2]
	pre[3] = f[1] + f[2] + f[3]
	var i int64
	for i = 4; i <= n; i++ {
		f[i] = pre[i-1] % m
		var lst int64 = -1
		var tmp int64 = 0
		var j int64
		for j = 2; j*j <= i; j++ {
			if j == 2 {
				lst = i / j
				tmp = ((tmp%m+((i%m-lst%m)%m*f[j-1]%m)%m)%m + f[i/j]%m) % m
				continue
			}
			t := lst
			lst = i / j
			tmp = ((tmp%m+((t%m-lst%m)%m*f[j-1]%m)%m)%m + f[i/j]%m) % m
		}
		if i/j == j-1 {
			t := lst
			lst = i / j
			tmp = (tmp%m + ((t%m-lst%m)%m*f[j-1]%m)%m) % m
		}
		f[i] = (f[i]%m + tmp%m) % m
		pre[i] = (pre[i-1]%m + f[i]%m) % m
	}
	fmt.Fprintln(out, f[n])
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1558B(in io.Reader, out io.Writer) {
	min := func(a, b int) int {
		if a > b {
			return b
		}
		return a
	}

	var n, m int
	Fscan(in, &n, &m)
	f := make([]int, n+2)
	f[n] = 1
	for i := n - 1; i > 0; i-- {
		f[i] = f[i+1] * 2 % m
		for j := 2; j*i <= n; j++ {
			f[i] = (f[i] + (f[i*j]-f[min((i+1)*j, n+1)]+m)%m) % m
		}
	}
	Fprint(out, (f[1]-f[2]+m)%m)
}

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

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	f := make([]int, n+1)
	s := make([]int, n+1)

	f[1] = 1
	s[1] = 1
	for i := 2; i <= n; i++ {
		f[i] = s[i-1]
		p := i

		if i <= 5 {
			for j := 2; j <= i; j++ {
				f[i] = (f[i] + f[i/j]) % m
			}
		} else {
			/*	fmt.Println(i, ": ")
				for j := 2; j <= i; j++ {
					fmt.Print(i/j, " ")
				}
				fmt.Println()*/

			for j := 2; j < i; j++ {
				if j-1 > i/j {
					break
				}
				if j-1 == i/j {
					//	fmt.Println(i, i/j, p-i/j, "x", j-1)
					f[i] = int((int64(f[i]) + int64(p-i/j)*int64(f[j-1])) % int64(m))
					break
				}
				//fmt.Println(i, i/j, p-i/j, "x", j-1)
				f[i] = int((int64(f[i]) + (int64(p-i/j) * int64(f[j-1]))) % int64(m))
				f[i] = (f[i] + f[i/j]) % m
				p = i / j
			}
		}

		s[i] = (s[i-1] + f[i]) % m
	}

	fmt.Println(f[n])
}

package main

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

var (
	in = bufio.NewReader(os.Stdin)
	dp []int64
)

func main() {
	var test int = 1
	//fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func init() {
	dp = make([]int64, 1000000)
}

func solve() {
	var n, internalm int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &internalm)
	solve2(n, 0)
	fmt.Println(dp[n] % internalm)

}

func solve2(n int64, tempCount int64) int64 {
	if n < 1 {
		return 0
	}
	if n == 1 {
		return 1
	}
	if dp[n] != 0 {
		return dp[n]
	}
	var currentAns int64
	for i := 1; i < int(n); i++ {
		currentAns += solve2(n-int64(i), tempCount+1)
	}
	for i := 2; i <= int(n); i++ {
		currentAns += solve2(int64(math.Floor(float64(n/int64(i)))), tempCount+1)
	}
	dp[n] = currentAns
	return currentAns
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func min(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

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


Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.  The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.

The first line contains two space-separated integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 109). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.

package main

import "fmt"

func main() {
	var n, k int64
	fmt.Scanln(&n, &k)
	lo, hi := int64(0), k
	for lo <= hi {
		x := (lo + hi) >> 1
		if (k+k-x-1)*x/2+1 >= n {
			hi = x - 1
		} else {
			lo = x + 1
		}
	}
	if lo < k {
		fmt.Println(lo)
	} else {
		fmt.Println(-1)
	}
}

package main

import (
	"fmt"
)

func sum(k, num int64) int64 {
	return num * k - (num - 1) * (num + 2) / 2
	//return num * ((k-1)+(k - num))/2 + 1
}

func run(n, k int64) {
	var i, j, mid int64
	i, j = 0, k
	for i < j {
		mid = (i + j) >> 1
		s := sum(k, mid)
		if s < n {
			i = mid + 1
		} else {
			j = mid
		}
	}
	mid = (i + j) >> 1
	if sum(k, mid) < n {
		fmt.Println(-1)
	} else {
		fmt.Println((i + j) >> 1)
	}
}

func main() {
	var n, k int64
	for _, err := fmt.Scanf("%d %d", &n, &k); err == nil; _, err = fmt.Scanf("%d %d", &n, &k) {
		run(n, k)
	}
}

package main

import (
	"fmt"
)

func sum(k, num int64) int64 {
	return num * ((k-1)+(k - num))/2 + 1
}

func run(n, k int64) {
	var i, j, mid int64
	i, j = 0, k-1
	mid = (i + j) >> 1
	if sum(k, j) < n {
		fmt.Println(-1)
		return
	}
	for i < j {
		s := sum(k, mid)
		if s >= n {
			j = mid
		} else {
			i = mid + 1
		}
		mid = (i + j) >> 1
	}
	fmt.Println(mid)
}

func main() {
	var n, k int64
	for _, err := fmt.Scanf("%d %d", &n, &k); err == nil; _, err = fmt.Scanf("%d %d", &n, &k) {
		run(n, k)
	}
}

package main

import (
	"fmt"
)

func sum(k, num int64) int64 {
	return num * ((k-1)+(k - num))/2 + 1
}

func run(n, k int64) {
	var i, j, mid int64
	i, j = 1, k-1
	mid = (i + j) >> 1
	if sum(k, j) < n {
		fmt.Println(-1)
		return
	}
	for i < j {
		s := sum(k, mid)
		if s >= n {
			j = mid
		} else {
			i = mid + 1
		}
		mid = (i + j) >> 1
	}
	fmt.Println(mid)
}

func main() {
	var n, k int64
	for _, err := fmt.Scanf("%d %d", &n, &k); err == nil; _, err = fmt.Scanf("%d %d", &n, &k) {
		run(n, k)
	}
}

package main

import (
	"fmt"
)

func sum(k, num int64) int64 {
	return num * ((k-1)+(k - num))/2 + 1
}

func run(n, k int64) {
	//fmt.Println("------------------", n, k)
	var i, j, mid int64
	i, j = 1, k-1
	mid = (i + j) >> 1
	if sum(k, j) < n {
		fmt.Println(-1)
		return
	}
	for i < j {
		s := sum(k, mid)
		if s > n {
			j = mid - 1
		} else {
			i = mid + 1
		}
		mid = (i + j) >> 1
	}
	fmt.Println(mid)
}

func main() {
	var n, k int64
	for _, err := fmt.Scanf("%d %d", &n, &k); err == nil; _, err = fmt.Scanf("%d %d", &n, &k) {
		run(n, k)
	}
}

package main

import (
	"fmt"
)

func sum(k, num int64) int64 {
	return num * ((k-1)+(k - num))/2 + 1
}

func run(n, k int64) {
	var i, j, mid int64
	i, j = 1, k-1
	mid = (i + j) >> 1
	if sum(k, j) < n {
		fmt.Println(-1)
		return
	}
	for i < j {
		if sum(n, mid) > n {
			j = mid - 1
		} else {
			i = mid + 1
		}
		mid = (i + j) >> 1
	}
	fmt.Println(mid)
}

func main() {
	var n, k int64
	for _, err := fmt.Scanf("%d %d", &n, &k); err == nil; _, err = fmt.Scanf("%d %d", &n, &k) {
		run(n, k)
	}
}


THE SxPLAY & KIVΛ - 漂流 KIVΛ & Nikki Simmons - PerspectivesWith a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.The space can be considered a 2D plane, with an infinite number of data nodes, indexed from $$$0$$$, with their coordinates defined as follows:  The coordinates of the $$$0$$$-th node is $$$(x_0, y_0)$$$  For $$$i > 0$$$, the coordinates of $$$i$$$-th node is $$$(a_x \cdot x_{i-1} + b_x, a_y \cdot y_{i-1} + b_y)$$$ Initially Aroma stands at the point $$$(x_s, y_s)$$$. She can stay in OS space for at most $$$t$$$ seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point $$$(x_s, y_s)$$$ to warp home.While within the OS space, Aroma can do the following actions:  From the point $$$(x, y)$$$, Aroma can move to one of the following points: $$$(x-1, y)$$$, $$$(x+1, y)$$$, $$$(x, y-1)$$$ or $$$(x, y+1)$$$. This action requires $$$1$$$ second.  If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs $$$0$$$ seconds. Of course, each data node can be collected at most once. Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within $$$t$$$ seconds?

The first line contains integers $$$x_0$$$, $$$y_0$$$, $$$a_x$$$, $$$a_y$$$, $$$b_x$$$, $$$b_y$$$ ($$$1 \leq x_0, y_0 \leq 10^{16}$$$, $$$2 \leq a_x, a_y \leq 100$$$, $$$0 \leq b_x, b_y \leq 10^{16}$$$), which define the coordinates of the data nodes. The second line contains integers $$$x_s$$$, $$$y_s$$$, $$$t$$$ ($$$1 \leq x_s, y_s, t \leq 10^{16}$$$) – the initial Aroma's coordinates and the amount of time available.

Print a single integer — the maximum number of data nodes Aroma can collect within $$$t$$$ seconds.

NoteIn all three examples, the coordinates of the first $$$5$$$ data nodes are $$$(1, 1)$$$, $$$(3, 3)$$$, $$$(7, 9)$$$, $$$(15, 27)$$$ and $$$(31, 81)$$$ (remember that nodes are numbered from $$$0$$$).In the first example, the optimal route to collect $$$3$$$ nodes is as follows:   Go to the coordinates $$$(3, 3)$$$ and collect the $$$1$$$-st node. This takes $$$|3 - 2| + |3 - 4| = 2$$$ seconds.  Go to the coordinates $$$(1, 1)$$$ and collect the $$$0$$$-th node. This takes $$$|1 - 3| + |1 - 3| = 4$$$ seconds.  Go to the coordinates $$$(7, 9)$$$ and collect the $$$2$$$-nd node. This takes $$$|7 - 1| + |9 - 1| = 14$$$ seconds. In the second example, the optimal route to collect $$$2$$$ nodes is as follows:   Collect the $$$3$$$-rd node. This requires no seconds.  Go to the coordinates $$$(7, 9)$$$ and collect the $$$2$$$-th node. This takes $$$|15 - 7| + |27 - 9| = 26$$$ seconds. In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1292B(_r io.Reader, _w io.Writer) {
	type point struct{ x, y int64 }
	abs := func(x int64) int64 {
		if x < 0 {
			return -x
		}
		return x
	}
	dis := func(a, b point) int64 { return abs(a.x-b.x) + abs(a.y-b.y) }

	var ax, ay, bx, by, tt int64
	var p, st point
	Fscan(_r, &p.x, &p.y, &ax, &ay, &bx, &by, &st.x, &st.y, &tt)
	ps := []point{}
	for ; p.x < 9e16 && p.y < 9e16; p.x, p.y = ax*p.x+bx, ay*p.y+by {
		ps = append(ps, p)
	}

	ans := 0
	for i, p := range ps {
		t := tt
		if d := dis(st, p); d <= t {
			t -= d
			c := 1
			for j := i; j > 0; j-- {
				if d := dis(ps[j], ps[j-1]); d <= t {
					t -= d
					c++
				} else {
					break
				}
			}
			if i+1 < len(ps) {
				if d := dis(ps[0], ps[i+1]); d <= t {
					t -= d
					c++
					for j := i + 2; j < len(ps); j++ {
						if d := dis(ps[j], ps[j-1]); d <= t {
							t -= d
							c++
						} else {
							break
						}
					}
				}
			}
			if c > ans {
				ans = c
			}
		}
	}
	Fprint(_w, ans)
}

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

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 1 << 60

	for x[len(x)-1] < (mat-bx)/ax && y[len(y)-1] < (mat-by)/ay {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	ans := 0

	for i := 0; i < len(x); i++ {
		for j := i; j < len(x); j++ {
			ltor := x[j]-x[i]+y[j]-y[i]
			tol := abs(xs-x[i])+abs(ys-y[i])
			tor := abs(xs-x[j])+abs(ys-y[j])

			if t >= ltor+tor || t >= tol+ltor {
				// fmt.Println(ltor,tol,ltor+tor,j,i)
				ans = max(ans, j-i+1)
			}
		}
	}

	fmt.Println(ans)
	// fmt.Println(x)

}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1292B(_r io.Reader, _w io.Writer) {
	type point struct{ x, y int64 }
	abs := func(x int64) int64 {
		if x < 0 {
			return -x
		}
		return x
	}
	dis := func(a, b point) int64 { return abs(a.x-b.x) + abs(a.y-b.y) }

	var ax, ay, bx, by, tt int64
	var p, st point
	Fscan(_r, &p.x, &p.y, &ax, &ay, &bx, &by, &st.x, &st.y, &tt)
	ps := []point{}
	for ; p.x < 1e17 && p.y < 1e17; p.x, p.y = ax*p.x+bx, ay*p.y+by {
		ps = append(ps, p)
	}

	ans := 0
	for i, p := range ps {
		t := tt
		if d := dis(st, p); d <= t {
			t -= d
			c := 1
			for j := i; j > 0; j-- {
				if d := dis(ps[j], ps[j-1]); d <= t {
					t -= d
					c++
				} else {
					break
				}
			}
			if i+1 < len(ps) {
				if d := dis(ps[0], ps[i+1]); d <= t {
					t -= d
					c++
					for j := i + 2; j < len(ps); j++ {
						if d := dis(ps[j], ps[j-1]); d <= t {
							t -= d
							c++
						} else {
							break
						}
					}
				}
			}
			if c > ans {
				ans = c
			}
		}
	}
	Fprint(_w, ans)
}

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

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 100000000000000000

	for x[len(x)-1] < mat && y[len(y)-1] < mat {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	to := int64(0)
	ans := 0

	done := make([]bool, len(x))

	for {
		mi := int64(1 << 63 -1)
		next := -1
		for i := 0; i < len(x); i++ {
			if done[i] {
				continue
			}

			if mi > abs(xs-x[i])+abs(ys-y[i]) {
				next = i
				mi = abs(xs-x[i])+abs(ys-y[i])
			}
		}

		if next == -1 {
			break
		}

		if to+mi > t {
			break
		}

		ans++
		to += mi
		xs = x[next]
		ys = y[next]
		done[next] = true
	}

	fmt.Println(ans)

}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 1 << 60

	for x[len(x)-1]*ax+bx <= mat && y[len(y)-1]*ay+by < mat {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	ans := 0

	for i := 0; i < len(x); i++ {
		for j := i; j < len(x); j++ {
			ltor := x[j]-x[i]+y[j]-y[i]
			tol := abs(xs-x[i])+abs(ys-y[i])
			tor := abs(xs-x[j])+abs(ys-y[j])

			if t >= ltor+tor || t >= tol+ltor {
				// fmt.Println(ltor,tol,ltor+tor,j,i)
				ans = max(ans, j-i+1)
			}
		}
	}

	fmt.Println(ans)
	// fmt.Println(x)

}

package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

func calc(x,y,ax,ay,bx,by int64) (int64,int64) {
	return ax*x+bx,ay*y+by
}

func dist(x1,y1,x2,y2 int64) int64 {
	return abs(x1-x2)+abs(y1-y2)
}

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

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by := scanInt64()

	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	cs := make([]coordinate, 0)
	cs = append(cs, coordinate{x0,y0})

	li := int64(10000000000000000)

	for cs[len(cs)-1].x<li&&cs[len(cs)-1].y<li {
		nx,ny := calc(cs[len(cs)-1].x,cs[len(cs)-1].y,ax,ay,bx,by)
		cs = append(cs, coordinate{nx,ny})
	}

	ans := 0

	for i := 0; i < len(cs)-1; i++ {
		for j := 0; j < len(cs)-1; j++ {
			if dist(cs[i].x,cs[i].y,xs,ys) + dist(cs[j].x,cs[j].y,cs[i].x,cs[i].y) <= t {
				ans = max(ans, int(abs(int64(j)-int64(i))) + 1)
			}
		}
	}

	fmt.Println(ans)
}

type coordinate struct {
	x int64
	y int64
}

func min(a ...int64) int64 {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}

package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

func calc(x,y,ax,ay,bx,by int64) (int64,int64) {
	return ax*x+bx,ay*y+by
}

func dist(x1,y1,x2,y2 int64) int64 {
	return abs(x1-x2)+abs(y1-y2)
}

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

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by := scanInt64()

	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	cs := make([]coordinate, 0)
	cs = append(cs, coordinate{x0,y0})

	li := int64(100000000000000000)

	for cs[len(cs)-1].x<li&&cs[len(cs)-1].y<li {
		nx,ny := calc(cs[len(cs)-1].x,cs[len(cs)-1].y,ax,ay,bx,by)
		cs = append(cs, coordinate{nx,ny})
	}

	ans := 0

	for i := 0; i < len(cs); i++ {
		for j := 0; j < len(cs); j++ {
			c := min(dist(cs[j].x,cs[j].y,xs,ys), dist(cs[i].x,cs[i].y,xs,ys))
			c += dist(cs[j].x,cs[j].y,cs[i].x,cs[i].y)
			if c <= t {
				ans = max(ans, j - i + 1)
			}
		}
	}

	fmt.Println(ans)
}

type coordinate struct {
	x int64
	y int64
}

func min(a ...int64) int64 {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 100000000000000000

	for x[len(x)-1] < mat && y[len(y)-1] < mat {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	to := int64(0)
	ans := 0

	mi := int64(1 << 63 -1)
	z := -1
	for i := 0; i < len(x); i++ {
		d := abs(x[i]-xs)+abs(y[i]-ys)
		if mi > d {
			z = i
			mi = d
		}
	}

	if mi > t {
		fmt.Println(0)
		return
	}

	to += mi
	ans++

	r := int64(0)
	for i := z+1; i < len(x); i++ {
		r += abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
	}

	l := int64(0)
	for i := z-1; i >= 0; i-- {
		l += abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
	}

	if l > r {
		for i := z+1; i < len(x); i++ {
			next := abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
		to += r
		for i := z-1; i >= 0; i-- {
			next := abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
	} else {
		for i := z-1; i >= 0; i-- {
			next := abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
		to += l
		for i := z+1; i < len(x); i++ {
			next := abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
	}

	fmt.Println(ans)

}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 100000000000000000

	for x[len(x)-1] < mat && y[len(y)-1] < mat {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	to := int64(0)
	ans := 0

	mi := int64(1 << 63 -1)
	z := -1
	for i := 0; i < len(x); i++ {
		d := abs(x[i]-xs)+abs(y[i]-ys)
		if mi > d {
			z = i
			mi = d
		}
	}

	if mi > t {
		fmt.Println(0)
		return
	}

	to += mi
	ans++

	r := int64(0)
	for i := z+1; i < len(x); i++ {
		r += abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
	}

	l := int64(0)
	for i := z-1; i >= 0; i-- {
		l += abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
	}

	if l > r {
		for i := z+1; i < len(x); i++ {
			next := abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
		for i := z-1; i >= 0; i-- {
			next := abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
	} else {
		for i := z-1; i >= 0; i-- {
			next := abs(x[i]-x[i+1])+abs(y[i]-y[i+1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
		for i := z+1; i < len(x); i++ {
			next := abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
			if next+to > t {
				break
			}

			ans++
			to += next
		}
	}

	fmt.Println(ans)

}

package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

func calc(x,y,ax,ay,bx,by int64) (int64,int64) {
	return ax*x+bx,ay*y+by
}

func dist(x1,y1,x2,y2 int64) int64 {
	return abs(x1-x2)+abs(y1-y2)
}

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

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by := scanInt64()

	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	cs := make([]coordinate, 0)
	cs = append(cs, coordinate{x0,y0})

	li := int64(100000000000000000)

	for cs[len(cs)-1].x<li&&cs[len(cs)-1].y<li {
		nx,ny := calc(cs[len(cs)-1].x,cs[len(cs)-1].y,ax,ay,bx,by)
		cs = append(cs, coordinate{nx,ny})
	}

	f := make([]bool, len(cs))
	cnt := int64(0)
	ans := int64(0)

	nextx, nexty := xs , ys

	for cnt <= t {
		mi := int64(1<<63-1)
		index := -1
		x, y := int64(-1), int64(-1)

		for i,e := range cs {
			if f[i] {
				continue
			}

			if dist(nextx,nexty,e.x,e.y) < mi {
				mi = dist(nextx,nexty,e.x,e.y)
				index = i
				x, y = e.x, e.y
			}
		}

		if index == -1 {
			break
		}

		if cnt+mi > t {
			break
		}

		f[index] = true
		nextx, nexty = x, y
		cnt += mi
		ans++
	}

	fmt.Println(ans)
}

type coordinate struct {
	x int64
	y int64
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

func abs(a int64) int64 { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by :=scanInt64()
	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	x := []int64{x0}
	y := []int64{y0}

	const mat = 1 << 61

	for x[len(x)-1]*ax+bx < mat && y[len(y)-1]*ay+by < mat {
		next := len(x)-1
		x = append(x, ax*x[next]+bx)
		y = append(y, ay*y[next]+by)
	}

	ans := 0

	for i := 0; i < len(x); i++ {
		for j := i; j < len(x); j++ {
			ltor := x[j]-x[i]+y[j]-y[i]
			tol := abs(xs-x[i])+abs(ys-y[i])
			tor := abs(xs-x[j])+abs(ys-y[j])

			if t >= ltor+tor || t >= tol+ltor {
				// fmt.Println(ltor+tol,ltor+tor,j,i)
				ans = max(ans, j-i+1)
			}
		}
	}

	fmt.Println(ans)

}

package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

func calc(x,y,ax,ay,bx,by int64) (int64,int64) {
	return ax*x+bx,ay*y+by
}

func dist(x1,y1,x2,y2 int64) int64 {
	return abs(x1-x2)+abs(y1-y2)
}

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

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by := scanInt64()

	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	cs := make([]coordinate, 0)
	cs = append(cs, coordinate{x0,y0})

	li := int64(100000000000000000)

	for cs[len(cs)-1].x<li&&cs[len(cs)-1].y<li {
		nx,ny := calc(cs[len(cs)-1].x,cs[len(cs)-1].y,ax,ay,bx,by)
		cs = append(cs, coordinate{nx,ny})
	}

	stx, sty := cs[len(cs)-1].x,cs[len(cs)-1].y
	mi := abs(stx-xs)+abs(sty-ys)
	index := len(cs)-1

	for i,e := range cs {
		if dist(xs,ys,e.x,e.y) < mi {
			mi = dist(xs,ys,e.x,e.y)
			index = i
		}
	}

	cnt := int64(0)
	x, y := xs,ys
	ans := int64(0)

	for i := index; i >=0 ; i-- {
		if cnt+dist(x,y,cs[i].x,cs[i].y) <= t{
			cnt+=dist(x,y,cs[i].x,cs[i].y)
			x,y = cs[i].x,cs[i].y
			ans++
			// fmt.Println(x,y,cnt)
		}
	}

	for i := index+1; i < len(cs); i++ {
		if cnt+dist(x,y,cs[i].x,cs[i].y) <= t{
			cnt+=dist(x,y,cs[i].x,cs[i].y)
			x,y = cs[i].x,cs[i].y
			ans++
			// fmt.Println(x,y,cnt)
		}
	}

	fmt.Println(ans)
}

type coordinate struct {
	x int64
	y int64
}

package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

func calc(x,y,ax,ay,bx,by int64) (int64,int64) {
	return ax*x+bx,ay*y+by
}

func dist(x1,y1,x2,y2 int64) int64 {
	return abs(x1-x2)+abs(y1-y2)
}

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

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	x0 := scanInt64()
	y0 := scanInt64()
	ax := scanInt64()
	ay := scanInt64()
	bx := scanInt64()
	by := scanInt64()

	xs := scanInt64()
	ys := scanInt64()
	t := scanInt64()

	cs := make([]coordinate, 0)
	cs = append(cs, coordinate{x0,y0})

	li := int64(100000000000000000)

	for cs[len(cs)-1].x<li&&cs[len(cs)-1].y<li {
		nx,ny := calc(cs[len(cs)-1].x,cs[len(cs)-1].y,ax,ay,bx,by)
		cs = append(cs, coordinate{nx,ny})
	}

	f := make([]bool, len(cs))
	cnt := int64(0)
	ans := int64(0)

	nextx, nexty := xs , ys

	for cnt <= t {
		mi := int64(1<<63-1)
		index := -1

		for i,e := range cs {
			if f[i] {
				continue
			}

			if dist(nextx,nexty,e.x,e.y) < mi {
				mi = dist(xs,ys,e.x,e.y)
				index = i
			}
		}

		if index == -1 {
			break
		}

		if cnt+mi > t {
			break
		}

		f[index] = true
		cnt += mi
		ans++
	}

	fmt.Println(ans)
}

type coordinate struct {
	x int64
	y int64
}


Little Elephant loves magic squares very much.A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.  The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.

The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.

Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.

package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var a,b,c,d,e,f,g,h,i int
	fmt.Scan(&a,&b,&c,&d,&e,&f,&g,&h,&i)
	a=c+((f-d)/2)
	i=g+((d-f)/2)
	e=b+c-g+((f-d)/2)
	fmt.Println(a,b,c)
	fmt.Println(d,e,f)
	fmt.Println(g,h,i)
}

package main

import "fmt"

func check(d... int) bool {
    for _, v := range d {
        if v != d[0] { return false }
    }
    return true
}

func main() {
    var a [3][3]int
    total := 0
    for i := 0; i < 3; i++ {
        for j := 0; j < 3; j++ {
            fmt.Scan(&a[i][j])
            total += a[i][j]
        }
    }
    total /= 2
    for i := 0; i < 3; i++ {
        t := total
        for j := 0; j < 3; j++ { t -= a[i][j] }
        a[i][i] = t
    }
    for i := 0; i < 3; i++ {
        for j := 0; j < 3; j++ {
            fmt.Print(a[i][j])
            if j == 2 { fmt.Println() } else { fmt.Print(" ") }
        }
    }
}


There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.

Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.

Print a single number — the minimum possible number of segments of the polyline.

NoteThe variant of the polyline in the first sample:  The variant of the polyline in the second sample:  The variant of the polyline in the third sample:

package main

import "fmt"

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

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

func isBetween(a, b, c int) bool {
    return min(a, b) <= c && c <= max(a, b)
}

func f(i, j, k int, x, y [3]int) bool {
    return (x[k] == x[i] || x[k] == x[j]) && isBetween(y[i], y[j], y[k]) || (y[k] == y[i] || y[k] == y[j]) && isBetween(x[i], x[j], x[k])
}

func main() {
    var x, y [3]int
    for i := 0; i < 3; i++ {
        fmt.Scanf("%d %d\n\r", &x[i], &y[i])
    }
//    for i := 0; i < 3; i++ {
//        fmt.Printf("%d %d\n\r", x[i], y[i])
//    }
    if (x[0] == x[1] && x[1] == x[2] || y[0] == y[1] && y[1] == y[2]) {
        fmt.Println("1")
    } else if (f(0, 1, 2, x, y) || f(0, 2, 1, x, y) || f(1, 2, 0, x, y)) {
        fmt.Println("2")
    } else {
        fmt.Println("3")
    }
}

package main

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

type vec struct{ x, y int64 }

func (a vec) sub(b vec) vec   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64 { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int64 { return a.x*b.y - a.y*b.x }

// github.com/EndlessCheng/codeforces-go
func CF617D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	f := func(a, b, c vec) bool {
		a, b = b.sub(a), c.sub(a)
		return (a.x == 0 || a.y == 0 || b.x == 0 || b.y == 0) && a.dot(b) <= 0
	}
	var a, b, c vec
	Fscan(in, &a.x, &a.y, &b.x, &b.y, &c.x, &c.y)
	if d := b.sub(a); (d.x == 0 || d.y == 0) && d.det(c.sub(b)) == 0 {
		Fprint(out, 1)
	} else if f(a, b, c) || f(b, a, c) || f(c, a, b) {
		Fprint(out, 2)
	} else {
		Fprint(out, 3)
	}
}

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

package main

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

type vec struct{ x, y int64 }

func (a vec) sub(b vec) vec   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64 { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int64 { return a.x*b.y - a.y*b.x }

// github.com/EndlessCheng/codeforces-go
func CF617D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	f := func(a, b, c vec) bool {
		a, b = b.sub(a), c.sub(a)
		return a.x == 0 && b.y == 0 || a.y == 0 && b.x == 0
	}
	var a, b, c vec
	Fscan(in, &a.x, &a.y, &b.x, &b.y, &c.x, &c.y)
	if b.sub(a).det(c.sub(b)) == 0 {
		Fprint(out, 1)
	} else if f(a, b, c) || f(b, a, c) || f(c, a, b) {
		Fprint(out, 2)
	} else {
		Fprint(out, 3)
	}
}

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

package main

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

type vec struct{ x, y int64 }

func (a vec) sub(b vec) vec   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64 { return a.x*b.x + a.y*b.y }
func (a vec) det(b vec) int64 { return a.x*b.y - a.y*b.x }

// github.com/EndlessCheng/codeforces-go
func CF617D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	f := func(a, b, c vec) bool { return b.sub(a).dot(c.sub(a)) == 0 }
	var a, b, c vec
	Fscan(in, &a.x, &a.y, &b.x, &b.y, &c.x, &c.y)
	if b.sub(a).det(c.sub(b)) == 0 {
		Fprint(out, 1)
	} else if f(a, b, c) || f(b, a, c) || f(c, a, b) {
		Fprint(out, 2)
	} else {
		Fprint(out, 3)
	}
}

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


As you have noticed, there are lovely girls in Arpa’s land.People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi.  Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i).

The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush.

If there is no t satisfying the condition, print -1. Otherwise print such smallest t.

NoteIn the first sample suppose t = 3. If the first person starts some round:The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.The process is similar for the second and the third person.If the fourth person starts some round:The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa.

package main

import "fmt"

type crushes []int

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

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

func lcmm(a ...int) int64 {
	l := int64(a[0])
	for _, v := range a {

		l = lcm(l, int64(v))
	}
	return l
}

func (cr crushes) CountStepsToReturn(start int) int {
	cnt := 1
	cur := start
	for cnt <= len(cr) {
		cur = cr[cur]
		if cur == start {
			break
		}
		cnt++
	}
	if cnt > len(cr) {
		return -1
	}
	return cnt
}

func main() {
	var n int
	fmt.Scan(&n)
	var cr crushes = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cr[i])
		cr[i]--
	}
	min := make([]int, n)
	var ans int64
	for i := 0; i < n; i++ {
		m := cr.CountStepsToReturn(i)
		if m == -1 {
			ans = -1
			break
		} else if m%2 == 0 {
			m = m / 2
		}
		min[i] = m
	}
	if ans != -1 {
		ans = lcmm(min...)
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"math/big"
)

func main() {
	n := 0
	fmt.Scanf("%d\n", &n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &crush[i])
		crush[i]--
	}

	// Checks zero in-degree.
	indeg := make([]int, n)
	for i := 0; i < n; i++ {
		indeg[crush[i]]++
	}
	for _, in := range indeg {
		if in == 0 {
			fmt.Println(-1)
			return
		}
	}

	// Collects sizes of loops.
	sizes := make([]int, 0)
	visited := make([]bool, n)
	for first := 0; first < n; first++ {
		if !visited[first] {
			visited[first] = true
			size := 1
			for x := crush[first]; !visited[x]; x = crush[x] {
				visited[x] = true
				size++
			}
			sizes = append(sizes, size)
		}
	}

	ans := big.NewInt(1)
	for _, size := range sizes {
		var k *big.Int
		if size%2 == 0 {
			k = big.NewInt(int64(size / 2))
		} else {
			k = big.NewInt(int64(size))
		}
		g := new(big.Int).GCD(nil, nil, ans, k)
		ans.Div(ans, g)
		ans.Mul(ans, k)
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"math/big"
)

func main() {
	n := 0
	fmt.Scanf("%d\n", &n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &crush[i])
		crush[i]--
	}

	sizes := make([]int, 0)
	visited := make([]bool, n)
	for first := 0; first < n; first++ {
		if !visited[first] {
			visited[first] = true
			size := 1
			x := crush[first]
			for !visited[x] {
				visited[x] = true
				size++
				x = crush[x]
			}
			if x != first {
				fmt.Println(-1)
				return
			}
			sizes = append(sizes, size)
		}
	}

	ans := big.NewInt(1)
	for _, size := range sizes {
		var k *big.Int
		if size%2 == 0 {
			k = big.NewInt(int64(size / 2))
		} else {
			k = big.NewInt(int64(size))
		}
		g := new(big.Int).GCD(nil, nil, ans, k)
		ans.Div(ans, g)
		ans.Mul(ans, k)
	}
	fmt.Println(ans)
}

package main

import "fmt"

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

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

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := int64(1)
	for i := 0; i < n; i++ {
		node := i
		for k := 1; k <= n; k++ {
			node = crush[node]
			if node == i {
				if k%2 == 0 {
					k /= 2
				}
				ans = lcm(ans, int64(k))
				goto start
			}
		}
		ans = -1
		break
	start:
	}
	fmt.Println(ans)
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1<<13)
	writer := bufio.NewWriterSize(os.Stdout, 1<<13)
	n := ReadInt(reader)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt(reader) - 1
	}
	fmt.Fprintln(writer, solve(a))
	writer.Flush()
}

func solve(a []int) int64 {
	n := len(a)
	res := int64(0)
	reached := make([]bool, n)
	for i := 0; i < n; i++ {
		if !reached[i] {
			k := i
			count := int64(0)
			for !reached[k] {
				reached[k] = true
				k = a[k]
				count++
			}
			if k != i {
				return -1
			}
			if count == 0 {
				continue
			}
			if count%2 == 0 {
				count /= 2
			}
			if res == 0 {
				res = count
			} else {
				res = lcm(res, count)
			}
		}
	}
	return res
}

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

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

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

func ReadInt(reader *bufio.Reader) int {
	return int(ReadInt64(reader))
}

func ReadInt64(reader *bufio.Reader) int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	sign := int64(1)
	if b == '-' {
		sign *= -1
		b, err = reader.ReadByte()
	}
	res := int64(0)
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res * sign
}

func isValid(b byte, err error) bool {
	return err == nil && (('0' <= b && b <= '9') || b == '-')
}

package main

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

func solve() {
    n := readInt()
    a, was := readIntArray(n), make([]bool, n)
    c, ok := []int{}, true
    for i := range a {
        cur, cnt := i, 0
        for !was[cur] {
            was[cur] = true
            cur = a[cur]-1
            cnt++
        }

        if cnt%2 == 0 {
            cnt /= 2
        }

        if cur != i {
            ok = false
        } else {
            if cnt > 0 {
                c = append(c, cnt)
            }
        }
    }
    ans := -1
    if ok {
        ans = 1
        for d := 2; d < 101; d++ {
            mul := 1
            for i := range c {
                curMul := 1
                for c[i]%d == 0 {
                    c[i] /= d
                    curMul *= d
                }
                if curMul > mul {
                    mul = curMul
                }
            }
            ans *= mul
        }
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

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

// IO

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

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

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

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

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

var n, cntGroup int
var crush, din, group []int
var t []int64

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

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

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	fmt.Fscanf(bufin, "%d\n", &n)

	crush = make([]int, n+1)
	din = make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(bufin, "%d\n", &crush[i])
		din[crush[i]]++
	}

	for i := 1; i <= n; i++ {
		if din[i] != 1 {
			fmt.Fprintf(bufout, "-1\n")
			return
		}
	}

	t = make([]int64, n+1)
	group = make([]int, n+1)
	cntGroup = 0

	for i := 1; i <= n; i++ {
		if group[i] == 0 {
			cntGroup++
			cntMember := int64(1)
			group[i] = cntGroup
			for j := crush[i]; group[j] == 0; j = crush[j] {
				cntMember++
				group[j] = cntGroup
			}
			if cntMember%2 == 1 {
				t[cntGroup] = cntMember
			} else {
				t[cntGroup] = cntMember / 2
			}
		}
	}

	r := t[1]
	for i := 2; i <= cntGroup; i++ {
		r = lcm(r, t[i])
	}

	fmt.Fprintf(bufout, "%d\n", r)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int
	fmt.Fscanln(r, &n)

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

	fmt.Fprintln(w, f(cs))
}

func f(cs []int) int {
	gs := graphs(cs)

	if len(gs) == 0 {
		return -1
	}

	for i, g := range gs {
		if g%2 == 0 {
			gs[i] = g / 2
		}
	}

	if len(gs) == 1 {
		return gs[0]
	}

	return lcmm(gs...)
}

func graphs(cs []int) []int {
	seen := make(map[int]bool, len(cs))

	var ls []int

	for j, c := range cs {
		i := j + 1

		if seen[i] {
			continue
		}

		if cs[i-1] == i {
			seen[i] = true
			seen[cs[i-1]] = true
			ls = append(ls, 1)
			continue
		}

		l := 2

		for ; ; l++ {
			seen[c] = true
			next := cs[c-1]
			if next == i {
				break
			}
			if seen[next] {
				return nil
			}
			c = next
		}
		seen[i] = true
		ls = append(ls, l)
	}
	return ls
}

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

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

func lcmm(xs ...int) int {
	r := 1
	for _, x := range xs {
		r = lcm(r, x)
	}
	return r
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
4
2 3 1 4
`,
			want: `3`,
		},
		{
			in: `
4
4 4 4 4
`,
			want: `-1`,
		},
		{
			in: `
4
2 1 4 3
`,
			want: `1`,
		},
		{
			in: `
5
2 3 1 5 4
`,
			want: `3`,
		},
		{
			in: `
7
2 3 1 5 6 7 4
`,
			want: `6`,
		},
		{
			in: `
5
2 4 3 1 2
`,
			want: `-1`,
		},
		{
			in: `
10
8 10 4 3 2 1 9 6 5 7
`,
			want: `15`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	group := make([]int, N + 1)
	groupCount := make([]int, N + 1)
	g := 1
	for i := 0; i < N; i++ {
		if group[i] == 0 {
			count := 1
			group[i] = g
			k := A[i] - 1
			for k != i {
				if (group[k] > 0) {
					fmt.Println(-1)
					return
				}
				group[k] = g
				k = A[k] - 1
				count++
			}
			groupCount[g] = count
			g++
		}
	}
	ans := int64(1)
	for i := 1; i < g; i++ {
		if groupCount[i] % 2 == 0 {
			ans = lcm(ans, int64(groupCount[i] / 2))
		} else {
			ans = lcm(ans, int64(groupCount[i]))
		}
	}
	fmt.Println(ans)
}

func lcm(a, b int64) int64 {
	return a / gcd(a, b) * b
}
func gcd(a, b int64) int64 {
	for b > 0 {
		a, b = b, a % b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import "fmt"

func getCrush(x, t int, crush []int) int {
	for i := 0; i < t; i++ {
		x = crush[x]
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := -1
	for t := 1; t <= n*n; t++ {
		flag := true
		for x := 0; x < n; x++ {
			y := getCrush(x, t, crush)
			if x != getCrush(y, t, crush) {
				flag = false
				break
			}
		}
		if flag {
			ans = t
			break
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

type crushes []int

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

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

func lcmm(a ...int) int {
	l := a[0]
	for _, v := range a {
		l = lcm(l, v)
	}
	return l
}

func (cr crushes) CountStepsToReturn(start int) int {
	cnt := 1
	cur := start
	for cnt <= len(cr) {
		cur = cr[cur]
		if cur == start {
			break
		}
		cnt++
	}
	if cnt > len(cr) {
		return -1
	}
	return cnt
}

func main() {
	var n int
	fmt.Scan(&n)
	var cr crushes = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cr[i])
		cr[i]--
	}
	min := make([]int, n)
	var ans int
	for i := 0; i < n; i++ {
		m := cr.CountStepsToReturn(i)
		if m == -1 {
			ans = -1
			break
		} else if m%2 == 0 {
			m = m / 2
		}
		min[i] = m
	}
	if ans != -1 {
		ans = lcmm(min...)
	}
	fmt.Println(ans)
}

package main

import "fmt"

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

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

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := 1
	for i := 0; i < n; i++ {
		node := i
		for k := 0; k < n; k++ {
			node = crush[node]
			if node == i {
				ans = lcm(ans, (k+1)/2)
				goto start
			}
		}
		ans = -1
		break
	start:
	}
	fmt.Println(ans)
}

package main

import "fmt"

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

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

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := 1
	for i := 0; i < n; i++ {
		node := i
		for k := 1; k <= n; k++ {
			node = crush[node]
			if node == i {
				if k%2 == 0 {
					k /= 2
				}
				ans = lcm(ans, k)
				goto start
			}
		}
		ans = -1
		break
	start:
	}
	fmt.Println(ans)
}

package main

import "fmt"

/*
func getCrush(x, t int, crush []int) int {
	if t > 0 {
		return getCrush(crush[x], t-1, crush)
	} else {
		return x
	}
}
*/

func getCrush(x, t int, crush []int) int {
	for i := 0; i < t; i++ {
		x = crush[x]
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := -1
	for t := 1; t <= n; t++ {
		flag := true
		for x := 0; x < n; x++ {
			y := getCrush(x, t, crush)
			if x != getCrush(y, t, crush) {
				flag = false
				break
			}
		}
		if flag {
			ans = t
			break
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func getCrush(x, t int, crush []int) int {
	if t > 0 {
		return getCrush(crush[x], t-1, crush)
	} else {
		return x
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	crush := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&crush[i])
		crush[i]--
	}
	ans := -1
	for t := 1; t <= n; t++ {
		flag := true
		for x := 0; x < n; x++ {
			y := getCrush(x, t, crush)
			if x != getCrush(y, t, crush) {
				flag = false
				break
			}
		}
		if flag {
			ans = t
			break
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int
	fmt.Fscanln(r, &n)

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

	fmt.Fprintln(w, f(cs))
}

func f(cs []int) int {
	gs := graphs(cs)

	if len(gs) == 0 {
		return -1
	}

	if len(gs) == 1 {
		return gs[0]
	}

	for i, g := range gs {
		if g%2 == 0 {
			gs[i] = g / 2
		}
	}

	return lcmm(gs...)
}

func graphs(cs []int) []int {
	seen := make(map[int]bool, len(cs))

	var ls []int

	for j, c := range cs {
		i := j + 1

		if seen[i] {
			continue
		}

		if cs[i-1] == i {
			seen[i] = true
			seen[cs[i-1]] = true
			ls = append(ls, 1)
			continue
		}

		l := 2

		for ; ; l++ {
			seen[c] = true
			next := cs[c-1]
			if next == i {
				break
			}
			if seen[next] {
				return nil
			}
			c = next
		}
		seen[i] = true
		ls = append(ls, l)
	}
	return ls
}

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

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

func lcmm(xs ...int) int {
	r := 1
	for _, x := range xs {
		r = lcm(r, x)
	}
	return r
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
4
2 3 1 4
`,
			want: `3`,
		},
		{
			in: `
4
4 4 4 4
`,
			want: `-1`,
		},
		{
			in: `
4
2 1 4 3
`,
			want: `1`,
		},
		{
			in: `
5
2 3 1 5 4
`,
			want: `3`,
		},
		{
			in: `
7
2 3 1 5 6 7 4
`,
			want: `6`,
		},
		{
			in: `
5
2 4 3 1 2
`,
			want: `-1`,
		},
		{
			in: `
10
8 10 4 3 2 1 9 6 5 7
`,
			want: `15`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int
	fmt.Fscanln(r, &n)

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

	fmt.Fprintln(w, f(cs))
}

func f(cs []int) int {
	gs := graphs(cs)

	if len(gs) == 0 {
		return -1
	}

	if len(gs) == 1 {
		return gs[0]
	}

	for i, g := range gs {
		if g%2 == 0 {
			gs[i] = g / 2
		}
	}

	return lcmm(gs...)
}

func graphs(cs []int) []int {
	seen := make(map[int]bool, len(cs))

	var ls []int

	for j, c := range cs {
		i := j + 1

		if seen[i-1] {
			continue
		}

		if cs[i-1] == i {
			seen[i] = true
			seen[cs[i-1]] = true
			ls = append(ls, 1)
			continue
		}

		l := 2

		for ; ; l++ {
			seen[c] = true
			next := cs[c-1]
			if next == i {
				break
			}
			if seen[next] {
				return nil
			}
			c = next
		}
		seen[i] = true
		ls = append(ls, l)
	}
	return ls
}

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

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

func lcmm(xs ...int) int {
	r := 1
	for _, x := range xs {
		r = lcm(r, x)
	}
	return r
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
4
2 3 1 4
`,
			want: `3`,
		},
		{
			in: `
4
4 4 4 4
`,
			want: `-1`,
		},
		{
			in: `
4
2 1 4 3
`,
			want: `1`,
		},
		{
			in: `
5
2 3 1 5 4
`,
			want: `3`,
		},
		{
			in: `
7
2 3 1 5 6 7 4
`,
			want: `6`,
		},
		{
			in: `
5
2 4 3 1 2
`,
			want: `-1`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int
	fmt.Fscanln(r, &n)

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

	fmt.Fprintln(w, f(cs))
}

func f(cs []int) int {
	gs := graphs(cs)

	if len(gs) == 0 {
		return -1
	}

	if len(gs) == 1 {
		return gs[0]
	}

	for i, g := range gs {
		if g%2 == 0 {
			gs[i] = g / 2
		}
	}

	return lcmm(gs...)
}

func graphs(cs []int) []int {
	seen := make(map[int]bool, len(cs))

	var ls []int

	for j, c := range cs {
		i := j + 1

		if seen[cs[c-1]] {
			continue
		}

		if cs[i-1] == i {
			seen[i] = true
			seen[cs[i-1]] = true
			ls = append(ls, 1)
			continue
		}

		l := 2

		for ; ; l++ {
			seen[c] = true
			next := cs[c-1]
			if next == i {
				break
			}
			if seen[next] {
				return nil
			}
			c = next
		}
		seen[i] = true
		ls = append(ls, l)
	}
	return ls
}

func gcd(a, b uint64) uint64 {
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

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

func lcmm(xs ...int) int {
	r := uint64(1)
	for _, x := range xs {
		r = lcm(r, uint64(x))
	}
	return int(r)
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
4
2 3 1 4
`,
			want: `3`,
		},
		{
			in: `
4
4 4 4 4
`,
			want: `-1`,
		},
		{
			in: `
4
2 1 4 3
`,
			want: `1`,
		},
		{
			in: `
5
2 3 1 5 4
`,
			want: `3`,
		},
		{
			in: `
7
2 3 1 5 6 7 4
`,
			want: `6`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}


Tonio has a keyboard with only two letters, "V" and "K".One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.

The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

NoteFor the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.

package main

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

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

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

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

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

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

func solve(s string) {
	ss := []byte(s)
	vk := []byte("VK")
	max := bytes.Count(ss, vk)
	for i := range ss {
		if ss[i] == 'V' {
			ss[i] = 'K'
		} else {
			ss[i] = 'V'
		}
		mx := bytes.Count(ss, vk)
		if mx > max {
			max = mx
		}
		if ss[i] == 'V' {
			ss[i] = 'K'
		} else {
			ss[i] = 'V'
		}
	}
	O(max, "\n")
}

package main

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

func solve() {
	str := readString()
	a := []byte(str)
	ans := 0
	for _, v := range []byte("VK") {
		for i := 0; i < len(a); i++ {
			prev := a[i]
			a[i] = v
			res := 0
			for j := 0; j < len(a)-1; j++ {
				if a[j] == 'V' && a[j+1] == 'K' {
					res++
					j++
				}
			}
			ans = max(ans, res)
			a[i] = prev
		}
	}
	fmt.Println(ans)
}

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

import (
	"fmt"
	"strings"
)

func vk(s string) int {
	return strings.Count(s, "VK")
}

func main() {
	var arr []byte
	var c byte
	var max int
	for {
		fmt.Scanf("%c", &c)
		if c == '\n' {
			break
		}
		arr = append(arr, c)
	}
	for i := 0; i < len(arr); i++ {
		if arr[i] == 'V' {
			arr[i] = 'K'
			if vk(string(arr)) > max {
				max = vk(string(arr))
			}
			arr[i] = 'V'
		} else {
			arr[i] = 'V'
			if vk(string(arr)) > max {
				max = vk(string(arr))
			}
			arr[i] = 'K'
		}
	}
	fmt.Println(max)
}


Madoka decided to entrust the organization of a major computer game tournament "OSU"!In this tournament, matches are held according to the "Olympic system". In other words, there are $$$2^n$$$ participants in the tournament, numbered with integers from $$$1$$$ to $$$2^n$$$. There are $$$n$$$ rounds in total in the tournament. In the $$$i$$$-th round there are $$$2^{n - i}$$$ matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament — is the last remaining participant.But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win — the participant on the left or right.But Madoka knows that tournament sponsors can change the winner in matches no more than $$$k$$$ times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change).  So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between $$$1$$$ and $$$3$$$ players). Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo $$$10^9 + 7$$$. Note that we need to minimize the answer, and only then take it modulo.

The first and the only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^5, 1 \le k \le \min(2^n - 1, 10^9)$$$) — the number of rounds in the tournament and the number of outcomes that sponsors can change.

Print exactly one integer — the minimum number of the winner modulo $$$10^9 + 7$$$

NoteIn the first example, there is only one match between players $$$1$$$ and $$$2$$$, so the sponsors can always make player $$$2$$$ wins.The tournament grid from the second example is shown in the picture in the statement.

package main

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

func modpow(x, n, mod int) int {
	if n == 0 {
		return 1 % mod
	}
	u := modpow(x, n/2, mod)
	u = (u * u) % mod
	if n&1 == 1 {
		u = (x * u) % mod
	}

	return u
}

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

func Solve(reader io.Reader, writer io.Writer) {
	mod := 1000000007

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	comb := 1
	ans := 1
	for i := 1; i <= Min(n, k); i++ {
		comb = (comb * (n - i + 1)) % mod
		comb = (comb * modpow(i, mod-2, mod)) % mod
		ans = (ans + comb) % mod

	}
	fmt.Fprintln(writer, ans)
}

func main() {
	// f, err := os.Open("data.txt")
	// if err != nil {
	// 	os.Exit(1)
	// }
	// defer f.Close()

	// reader := bufio.NewReader(f)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	Solve(reader, writer)
	writer.Flush()

}

package main

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

var P107 int = 1000000007

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

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

func Abs(a int) int {
	return Max(a, -a)
}

func Gcd(a, b int) int {
	min := Min(a, b)
	max := Max(a, b)
	if min == 0 {
		return max
	}

	for max%min != 0 {
		min, max = max%min, min
	}

	return min
}

func Lcm(a, b int) int {
	return a / Gcd(a, b) * b
}

var facs []int = make([]int, 100010)

func FacP(n, p int) int {
	if facs[n] != 0 {
		return facs[n]
	}

	result := 1
	facs[0] = 1
	for i := 1; i <= n; i++ {
		result = (result * i) % p
		facs[i] = result
	}

	return result
}

func ExpP(a, x, p int) int {
	if x == 0 {
		return 1
	}

	if x%2 == 0 {
		half := ExpP(a, x/2, p)
		return (half * half) % p
	} else {
		return ((a % p) * ExpP(a, x-1, p)) % p
	}
}

func CombP(n, c, p int) int {
	return (FacP(n, p) * ((ExpP(FacP(n-c, p), p-2, p) * ExpP(FacP(c, p), p-2, p)) % p)) % p
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())
	k = Min(k, n)

	result := 0
	for i := 0; i <= k; i++ {
		result = (result + CombP(n, i, P107)) % P107
	}

	wr.WriteString(strconv.Itoa(result) + "\n")
}

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


A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.

Input contains one integer number n (1 ≤ n ≤ 3000).

Output the amount of almost prime numbers between 1 and n, inclusive.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader, "%d", &n)
	count := 0
	for i := 6;i <= n;i ++ {
		prime_count := 0
		x := i
		for j := 2;j <= i;j ++ {
			if x % j == 0 {
				prime_count ++
				for x % j == 0 {
					x /= j
				}
			}
		}
		if prime_count == 2 {
			count ++
		}
	}
	fmt.Printf("%d", count)
}

package main

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

func main(){
	var n int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	a := make([]int, 3001)
	count := 0
	for i:=2; i<=n; i++ {
		for j:=2; j<i; j++ {
			if a[j] == 0 && i%j == 0 {
				a[i] += 1
			}
		}
		if a[i] == 2 {
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	w.Flush()
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  max := 3000
  primes := []int{}
  notPrime := make([]bool, max+1)
  pos := 1
  for {
    pos++
    for pos <= max && notPrime[pos] {
      pos++
    }
    if pos > max {
      break
    }
    primes = append(primes, pos)
    for i := 2*pos; i <= max; i += pos {
      notPrime[i] = true
    }
  }

  n := getI()
  result := 0
  for a := 1; a <= n; a++ {
    count := 0
    for _, b := range primes {
      if b >= a {
        break
      }
      if a%b == 0 {
        count++
      }
    }
    if count == 2 {
      result++
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func seive(n int64) int64 {
	var isPrime []bool = []bool{}
	var i int64
	var j int64
	for i = 0; i <= n; i++ {
		isPrime = append(isPrime, true)
	}
	var num = make([]int64, n+1)
	for i = 2; i <= (n); i++ {
		if isPrime[i] == true {
			for j = 2; j*i <= n; j++ {
				isPrime[j*i] = false
				num[j*i] += 1
			}
		}
	}
	var result int64 = 0
	for i = 2; i <= n; i++ {
		if num[i] == 2 {
			result++
		}
	}
	return result
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	var res int64
	res = seive(n)
	fmt.Println(res)
}

package main

import "fmt"

func main() {
	var w int
	_, _ = fmt.Scanf("%d", &w)
	simples := make([]int, w-1)
	for i := 2; i < w+1; i++ {
		simples[i-2] = i
	}

	for _, i := range simples {
		if i != -1 {
			for j := i * i; j <= w; j += i {
				simples[j-2] = -1
			}
		}
	}
	ans := 0

	for i := 2; i <= w; i++ {
		cnt := 2
		for _, v := range simples {
			if v != -1 && i%v == 0 {
				cnt--
			}
		}

		if cnt == 0 {
			ans += 1
		}
	}
	fmt.Println(ans)

}

package main

import (
	"fmt"
)

var (
	pr  = [...]int32{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}
	npr = int32(len(pr))
)

// num of prime factors
func npf(x int32) (ret int32) {
	i := int32(0)
	for i < npr && ret < 3 && x > 1 {
		d := pr[i]
		if d*d > x {
			ret++
			break
		}
		volt := false
		for x%d == 0 {
			volt = true
			x = x / d
		}
		if volt {
			ret++
		}
		i++
	}
	return
}

func main() {
	var n int32
	fmt.Scan(&n)
	s := int32(0)
	for i := int32(6); i <= n; i++ {
		//println(i, npf(i))
		if 2 == npf(i) {
			s++
		}
	}
	fmt.Println(s)

}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    p := make([]int,n+1)
    ans := 0
    for i := 2; i <= n; i++ {
        if p[i] == 0 {
            for a := i; a <= n; a += i {
                p[a]++
            }
        } else if p[i] == 2 {
            ans++
        }
    }
    fmt.Println(ans)
}

package main

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

func genPrime(max int) []int {
	primes := make([]int, 0)
	sieve := make([]bool, max+1)
	for i := 2; i < max+1; i++ {
		if sieve[i] == true {
			continue
		}
		primes = append(primes, i)
		for j := 2; i*j < max+1; j++ {
			sieve[i*j] = true
		}
	}
	return primes
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := 0
	if scanner.Scan() {
		line := scanner.Text()

		fmt.Sscanf(line, "%d", &n)
		primes := genPrime(n)

		almostPrime := 0

		for i := 2; i <= n; i++ {
			tmp := i
			factorCount := 0
			for _, j := range primes {
				if tmp%j == 0 {
					factorCount += 1
					if factorCount > 2 {
						break
					}
				}
				for tmp%j == 0 {
					tmp = tmp / j
				}
			}
			if factorCount == 2 {
				almostPrime += 1
			}
		}

		fmt.Println(almostPrime)
	}
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

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

var n int

func main() {
	fmt.Fscan(reader, &n)

	ans := 0
	for num := 0; num <= n; num++ {
		a := Divisor(num)
		sum := 0
		for i := 0; i < len(a); i++ {
			if IsPrime(a[i]) {
				sum++
			}
			if sum > 2 {
				break
			}
		}
		if sum == 2 {
			ans++
		}
	}

	fmt.Println(ans)
}

// IsPrime 素性测试
func IsPrime(n int) bool {
	for i := int(2); i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return n != 1
}

// Divisor 约数枚举
func Divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != n/i {
				res = append(res, n/i)
			}
		}
	}
	return
}

// 26A
package main

import (
	"fmt"
)

func main() {
	var d [3005]int
	var n int
	fmt.Scan(&n)
	for i := 2; i <= n; i++ {
		if d[i] != 0 {
			continue
		}
		for j := i; j <= n; j += i {
			d[j]++
		}
	}
	res := 0
	for i := 6; i <= n; i++ {
		if d[i] == 2 {
			res++
		}
	}
	fmt.Println(res)
}

// 26A-mic_rizal
package main

import (
	"fmt"
)

func main() {
	var v []int
	var cont, num, cou, l int
	v = append(v, 2)
	l++
	for i := 3; i < 3000; i += 2 {
		for j := 2; j < i; j++ {
			if i%j == 0 {
				cont++
				break
			}
		}
		if cont <= 0 {
			v = append(v, i)
			l++
		}
		cont = 0
	}
	cont = 0
	fmt.Scan(&num)
	for i := 1; i <= num; i++ {
		for j := 0; j < l; j++ {
			if i%v[j] == 0 {
				cont++
			}
		}
		if cont == 2 {
			cou++
		}
		cont = 0
	}
	fmt.Println(cou)
}

package main

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

const (
	BIG = 1024 * 1024 * 10
)

func readLine(r *bufio.Reader) string {
	bytes, _, err := r.ReadLine()
	if err != nil {
		log.Fatalln("Failed to read line")
	}

	return string(bytes)
}

func readInts(r *bufio.Reader) []int {
	elems := strings.Fields(readLine(r))

	ret := make([]int, len(elems))
	for i, el := range elems {
		tmp, err := strconv.ParseInt(el, 10, 64)
		if err != nil {
			log.Fatalf("Failed to parse number %v", el)
		}
		ret[i] = int(tmp)
	}

	return ret
}

type Sieve struct {
	n             int
	first, primes []int
}

type Factor struct {
	Base, Exp int
}

func NewSieve(n int) *Sieve {
	first := make([]int, n+1)
	primes := make([]int, 0)

	for i := 2; i <= n; i++ {
		if first[i] == 0 {
			first[i] = i
			primes = append(primes, i)
		}

		for j := 0; j < len(primes) && primes[j] <= first[i] && i*primes[j] <= n; j++ {
			first[i*primes[j]] = primes[j]
		}
	}

	ret := Sieve{n, first, primes}

	return &ret
}

func (s *Sieve) IsPrime(x int) (bool, error) {
	if s.n < x {
		return false, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}
	if x < s.primes[0] || x > s.primes[len(s.primes)-1] {
		return false, nil
	} else if x == s.primes[0] {
		return true, nil
	}
	low, high := 0, len(s.primes)-1
	for high-low > 1 {
		mid := (low + high) / 2
		if s.primes[mid] < x {
			low = mid
		} else {
			high = mid
		}
	}
	return s.primes[high] == x, nil
}

func (s *Sieve) Factors(x int) ([]Factor, error) {
	factors := make([]Factor, 0)

	if s.n < x {
		return factors, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}

	for x > 1 {
		pi := s.first[x]
		exp := 0
		for x > 1 && s.first[x] == pi {
			exp += 1
			x /= pi
		}
		factors = append(factors, Factor{pi, exp})
	}

	return factors, nil
}
func main() {
	r := bufio.NewReaderSize(os.Stdin, BIG)

	n := readInts(r)[0]
	s := NewSieve(n)

	total := 0
	for i := 1; i <= n; i++ {
		factors, _ := s.Factors(i)
		if len(factors) == 2 {
			total += 1
		}
	}

	fmt.Println(total)
}

// 26A
package main

import (
	"fmt"
)

func main() {
	var d [3005]int
	var n int
	fmt.Scan(&n)
	for i := 2; i <= n; i++ {
		if d[i] != 0 {
			continue
		}
		for j := i; j <= n; j += i {
			d[j]++
		}
	}
	res := 0
	for i := 6; i <= n; i++ {
		if d[i] == 2 {
			res++
		}
		fmt.Println(res)
	}
}