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
}


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

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


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


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

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


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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF766B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	for i, v := range a[2:] {
		if a[i]+a[i+1] > v {
			Fprint(out, "YES")
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	for i := n - 1; i >= 2; i-- {
		if array[i-1]+array[i-2] > array[i] {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func solve() {
	n := readInt()
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = readInt()
	}
	sort.Ints(v)
	for i := 2; i < n; i++ {
		a := int64(v[i-2])
		b := int64(v[i-1])
		c := int64(v[i])
		if a+b > c && a+c > b && b+c > a {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

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 max(a, 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 (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func CF766B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	if n > 44 {
		Fprint(out, "YES")
		return
	}
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	for i, v := range a[2:] {
		if a[i]+a[i+1] > v {
			Fprint(out, "YES")
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n := readInt()
	maj := make([]int, n)
	for i := range maj {
		maj[i] = readInt()
	}
	sort.Ints(maj)
	for i := 0; i <= len(maj)-3; i++ {
		if maj[i]+maj[i+1] > maj[i+2] {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

package main

import "fmt"
import "sort"
import "bufio"
import "os"
import "strconv"

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)

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

	for i := 0; scanner.Scan(); i++ {
		num, _ := strconv.Atoi(scanner.Text())
		nums[i] = num
	}
	sort.Ints(nums)

	var canFormTriangle bool
	for i := 2; i < n; i++ {
		if nums[i-2]+nums[i-1] > nums[i] {
			canFormTriangle = true
			break
		}
	}
	if canFormTriangle {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func frst() {
    fmt.Println("YES")
}
func scnd() {
    fmt.Println("NO")
}

func check(a int, b int, c int) bool {
    if a + b > c && b + c > a && a + c > b {
        return true
    } else {
        return false
    }
}

func main() {
    var n int
    scanf("%d\n", &n)
    var a = make([]int, n)
    for i := 0; i < n; i++ {
        scanf("%d", &a[i])
    }
    sort.Ints(a)
    for i := 0; i < n - 2; i++ {
        if check(a[i], a[i + 1], a[i + 2]) == true {
            frst()
            return
        }
    }
    if check(a[n - 2], a[n - 1], a[0]) == true {
        frst()
        return
    }
    if check(a[n - 1], a[0], a[1]) == true {
        frst()
        return
    }
    scnd()
}

package main

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

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	sort.Ints(A)

	for i := 0; i + 2 < N; i++ {
		if A[i] + A[i + 1] > A[i + 2] {
			io.Println("YES")
			return
		}
	}
	io.Println("NO")
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Solve(&io)
	io.FlushOutput()
}

package main

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

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 n int
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n int) {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		I(&a[i])
	}
	sort.Ints(a)
	for i := 0; i < len(a)-2; i++ {
		if a[i]+a[i+1] > a[i+2] {
			O("YES\n")
			return
		}
	}
	O("NO\n")
}

package main

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

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 n int
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n int) {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		I(&a[i])
	}
	sort.Ints(a)
	for i := 0; i < len(a)-2; i++ {
		if a[i]+a[i+1] >= a[i+2] {
			O("YES\n")
			return
		}
	}
	O("NO\n")
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n := readInt()
	maj := make([]int, n)
	for i := range maj {
		maj[i] = readInt()
	}
	sort.Ints(maj)
	a, b, c := int64(maj[len(maj)-3]), int64(maj[len(maj)-2]), int64(maj[len(maj)-1])
	if a*a+b*b < c*c {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n := readInt()
	maj := make([]int, n)
	for i := range maj {
		maj[i] = readInt()
	}
	sort.Ints(maj)
	a, b, c := int64(maj[0]), int64(maj[1]), int64(maj[len(maj)-1])
	if a*a+b*b < c*c {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n := readInt()
	maj := make([]int, n)
	for i := range maj {
		maj[i] = readInt()
	}
	sort.Ints(maj)
	a, b, c := int64(maj[0]), int64(maj[1]), int64(maj[len(maj)-1])
	fmt.Println(a*a+b*b < c*c)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n := readInt()
	maj := make([]int, n)
	for i := range maj {
		maj[i] = readInt()
	}
	sort.Ints(maj)
	a, b, c := int64(maj[len(maj)-3]), int64(maj[len(maj)-2]), int64(maj[len(maj)-1])
	if a*a+b*b > c*c {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


package main

import "fmt"

type key struct {
	lastIdx    int
	nDifferent int
}

var (
	n, m, k int
	cache   = make(map[key]int64)
)

// colorings will calculate how many different colorings are at a[0]..a[lastIdx], so that nDifferent for 0..lastIdx holds.
func colorings(lastIdx int, nDifferent int) (ret int64) {
	k := key{lastIdx, nDifferent}
	if r, ok := cache[k]; ok {
		return r
	}
	defer func() {
		cache[k] = ret
	}()

	// We have spent all our different brick possibilities.
	if nDifferent < 0 {
		return 0
	}

	if lastIdx == 0 {
		if nDifferent == 0 {
			// If there is only one brick remaining, it can have m different colors.
			return int64(m)
		}
		// But only, if there is exactly zero bricks different on its left.
		return 0
	}

	// There are p combinations for 0..lastIdx-1. For each combination:
	//   - there is (m-1) combinations with nDifferent that is the same
	//   - one combination with nDifferent less.
	lastIdxDifferent := colorings(lastIdx-1, nDifferent-1) * int64(m-1)
	lastIdxSame := colorings(lastIdx-1, nDifferent)
	// dprintf("lastIdx=%d, nDifferent=%d, noDiff=%d, diff=%d", lastIdx, nDifferent, noDiffChange, diffChange)

	return (lastIdxDifferent + lastIdxSame) % 998244353

	// m combinations where [lastIdx-1, lastIdx are the same]
	// m**2 - m combinations where [lastIdx-1 and lastIdx are different]
}

func dprintf(i string, a ...interface{}) {
	if false {
		fmt.Printf(i+"\n", a...)
	}
}

func main() {
	fmt.Scanf("%d %d %d", &n, &m, &k)
	fmt.Println(colorings(n-1, k))
	dprintf("%v", cache)
}

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m, k := 0, 0, 0
	fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
	f := make([][]int64, n+1)
	for i := 0; i < n+1; i++ {
		f[i] = make([]int64, k+1)
	}
	f[1][0] = int64(m)
	for i := 2; i < n+1; i++ {
		for j := 0; j < k+1; j++ {
			if j == 0 {
				f[i][j] = f[i-1][j]
			} else {
				f[i][j] = f[i-1][j] + f[i-1][j-1]*int64(m-1)
				f[i][j] %= mod
			}
		}
	}
	fmt.Fprintf(out, "%d\n", f[n][k])
	return
}

package main

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

const M int64 = 998244353
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
  fmt.Fprintf(writer, f, a...)
}

func scanf(f string, a ...interface{}) {
  fmt.Fscanf(reader, f, a...)
}

func sp(x, y int64) int64 {
  var mul, res int64 = x, 1
  for y != 0 {
    if y % 2 != 0 {
      res = (res * mul) % M
    }
    mul = (mul * mul) % M
    y /= 2
  }
  return res
}

func main() {
  defer writer.Flush()
  var n, m, k int
  scanf("%d%d%d", &n, &m, &k)
  fac := make([]int64, n+1)
  fac[0] = 1
  for i := 1; i <= n; i += 1 {
    fac[i] = (fac[i-1] * int64(i)) % M
  }

  sol := fac[n-1]
  sol = (sol * sp(fac[n-1-k], M-2)) % M
  sol = (sol * sp(fac[k], M-2)) % M
  sol = (sol * sp(int64(m-1), int64(k))) % M
  sol = (sol * int64(m)) % M
  printf("%d\n", sol)
}

package main

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

const M int = 998244353
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
  fmt.Fprintf(writer, f, a...)
}

func scanf(f string, a ...interface{}) {
  fmt.Fscanf(reader, f, a...)
}

func sp(x, y int) int {
  var mul, res int = x, 1
  for y != 0 {
    if y % 2 != 0 {
      res = (res * mul) % M
    }
    mul = (mul * mul) % M
    y /= 2
  }
  return res
}

func main() {
  defer writer.Flush()
  var n, m, k int
  scanf("%d%d%d", &n, &m, &k)

  fac := make([]int, n+1)
  fac[0] = 1
  for i := 1; i <= n; i += 1 {
    fac[i] = (fac[i-1] * i) % M
  }

  sol := fac[n-1]
  sol = (sol * sp(fac[n-1-k], M-2)) % M
  sol = (sol * sp(fac[k], M-2)) % M
  sol = (sol * sp(m-1, k)) % M
  sol = (sol * m) % M
  printf("%d\n", sol)
}

package main

import (
  "fmt"
)

const M int = 998244353

func sp(x, y int) int {
  var mul, res int = x, 1
  for y != 0 {
    if y % 2 != 0 {
      res = (res * mul) % M
    }
    mul = (mul * mul) % M
    y /= 2
  }
  return res
}

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

  fac := make([]int, n+1)
  fac[0] = 1
  for i := 1; i <= n; i += 1 {
    fac[i] = (fac[i-1] * i) % M
  }

  sol := fac[n-1]
  sol = (sol * sp(fac[n-1-k], M-2)) % M
  sol = (sol * sp(fac[k], M-2)) % M
  sol = (sol * sp(m-1, k)) % M
  sol = (sol * m) % M
  fmt.Printf("%d\n", sol)
}

package main

import (
  "fmt"
)

const M int = 998244353

func sp(x, y int) int {
  var mul, res int = x, 1
  for y != 0 {
    if y % 2 != 0 {
      res = (res * mul) % M
    }
    mul = (mul * mul) % M
    y /= 2
  }
  return res
}

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

  fac := make([]int, n+1)
  fac[0] = 1
  for i := 1; i <= n; i += 1 {
    fac[i] = (fac[i-1] * i) % M
  }

  sol := fac[n-1]
  sol = (sol * sp(fac[n-1-k], M-2)) % M
  sol = (sol * sp(fac[k], M-2)) % M
  sol = (sol * sp(m-1, k)) % M
  sol = (sol * m) % M
  fmt.Printf("%d\n", sol)
}

package main

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

const M int = 998244353
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) {
  fmt.Fprintf(writer, f, a...)
}

func scanf(f string, a ...interface{}) {
  fmt.Fscanf(reader, f, a...)
}

func sp(x, y int) int {
  var mul, res int = x, 1
  for y != 0 {
    if y % 2 != 0 {
      res = (res * mul) % M
    }
    mul = (mul * mul) % M
    y /= 2
  }
  return res
}

func main() {
  defer writer.Flush()
  var n, m, k int
  scanf("%d%d%d", &n, &m, &k)
  printf("%d %d %d\n", n, m, k);
  fac := make([]int, n+1)
  fac[0] = 1
  for i := 1; i <= n; i += 1 {
    fac[i] = (fac[i-1] * i) % M
  }

  sol := fac[n-1]
  sol = (sol * sp(fac[n-1-k], M-2)) % M
  sol = (sol * sp(fac[k], M-2)) % M
  sol = (sol * sp(m-1, k)) % M
  sol = (sol * m) % M
  printf("%d\n", sol)
}


// Author: sighduck
// URL: https://codeforces.com/contest/1143/problem/B

package main

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

func getLength(n int) int {
	length := 0
	for n > 0 {
		n /= 10
		length += 1

	}
	return length
}

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

func product(n int) int64 {
	product := int64(1)
	for n > 0 {
		product *= int64(n % 10)
		n /= 10
	}
	return product
}

func Solve(n int) int64 {
	base := 10
	maxProduct := int64(0)
	for n > 0 {
		maxProduct = max(maxProduct, product(n))
		n -= (n%base + 1)
		base *= 10
	}
	return maxProduct
}

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

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

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

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func main() {
	defer writer.Flush()
	ch := string("")
	scanf("%s", &ch)
	num := []byte(ch)
	s1 := uint64(1)
	for _, char := range num {
		s, _ := strconv.ParseUint(string(char), 10, 64)
		s1 *= s
	}
	for i, char := range num {
		if char == '0' {
			break
		}
		num1 := make([]byte, len(num))
		copy(num1, num)
		num1[i] = num[i] - 1
		s2 := uint64(1)
		for j, char := range num1 {
			var number uint64
			if j <= i {
				number, _ = strconv.ParseUint(string(char), 10, 64)
				if number == 0 {
					number = 1
				}
			} else {
				number = 9
			}
			s2 *= number
		}
		if s2 > s1 {
			s1 = s2
		}
	}
	printf("%d\n", s1)

}

package main

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

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

	var n int64
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]int64, 20)
	len := 0
	for n > 0 {
		mat[len] = n % int64(10)
		n /= 10
		len++
	}
	//for i := len - 1; i >= 0; i-- {
	//	if mat[i] == 0 {
	//		for j := i + 1; j < len; j++ {
	//			mat[j]--
	//			if mat[j] > 0 || (mat[j] == 0 && j == len-1) {
	//				for k := j - 1; k >= 0; k-- {
	//					mat[k] = 9
	//				}
	//				break
	//			}
	//		}
	//		break
	//	}
	//}
	//for i := len; i >= 0; i-- {
	//	if mat[i] > 0 {
	//		len = i + 1
	//		break
	//	}
	//}
	var le int64 = 1
	var ans int64 = 1
	var tmp int64 = 1
	for i := 0; i < len; i++ {
		ans *= mat[i]
		le *= 9
	}
	//fmt.Printf("-%d len=%d %v\n",ans,len,mat)

	for i := len - 1; i >= 0; i-- {
		le /= 9
		if mat[i] > 1 {
			if tmp*(mat[i]-1)*le > ans {
				ans = tmp * (mat[i] - 1) * le
			}
		} else if i == len-1 {
			if le > ans {
				ans = le
			}
		}else {
			break
		}
		tmp *= mat[i]
	}
	fmt.Printf("%d\n", ans)
}

package main

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

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

	var n int64
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]int64, 20)
	len := 0
	for n > 0 {
		mat[len] = n % int64(10)
		n /= 10
		len++
	}
	for i := len - 1; i >= 0; i-- {
		if mat[i] == 0 {
			for j := i + 1; j < len; j++ {
				mat[j]--
				if mat[j] > 0 || (mat[j] == 0 && j == len-1) {
					for k := j - 1; k >= 0; k-- {
						mat[k] = 9
					}
					break
				}
			}
			break
		}
	}
//	fmt.Printf("%v\n",mat)
	for i := len; i >= 0; i-- {
		if mat[i] > 0 {
			len = i + 1
			break
		}
	}
	var le int64 = 1
	var ans int64 = 1
	var tmp int64 = 1
	for i := 0; i < len; i++ {
		ans *= mat[i]
		le *= 9
	}
	//fmt.Printf("-%d len=%d %v\n",ans,len,mat)

	for i:=len-1;i>=0;i--{
		le/=9
		if mat[i] > 1{
			if tmp*(mat[i]-1)*le > ans{
				ans=tmp*(mat[i]-1)*le
			}
		}else if i==len-1{
			if le > ans{
				ans =le
			}
		}
		tmp *= mat[i]
	}
	fmt.Printf("%d\n",ans)
}

/*
URL:
https://codeforces.com/problemset/problem/1143/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	N []rune

	dp [20][2]int64
)

func main() {
	N = ReadRuneSlice()
	n := len(N)

	dp[0][0] = 1
	for i := 0; i < len(N); i++ {
		d := int64(N[i] - '0')

		dp[i+1][0] = dp[i][0] * d
		ChMax(&dp[i+1][1], dp[i][0]*(d-1))
		ChMax(&dp[i+1][1], dp[i][0])
		ChMax(&dp[i+1][1], dp[i][1]*9)
	}

	fmt.Println(Max(dp[n][0], dp[n][1]))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	if n < 10 {
		fmt.Fprintf(out, "%d\n", n)
		return
	}
	a := make([]int, 0)
	for n > 0 {
		a = append(a, n%10)
		n /= 10
	}
	b := make([]int, len(a))
	for i := 0; i < len(a); i++ {
		b[i] = a[len(a)-i-1]
	}
	ans := 1
	for i := 0; i < len(a); i++ {
		ans *= b[i]
	}
	tmp := 1
	for i := 1; i < len(a); i++ {
		tmp *= 9
	}
	if tmp > ans {
		ans = tmp
	}
	// c := make([]int, len(b))
	// for i := 0; i < len(b); i++ {
	// 	c[i] = b[i]
	// }

	for i := 0; i < len(b); i++ {
		if b[i] > 1 {
			tmp := 1
			for j := 0; j < i; j++ {
				tmp *= b[j]
			}
			tmp *= b[i] - 1
			for j := i + 1; j < len(b); j++ {
				tmp *= 9
			}
			if tmp > ans {
				ans = tmp
			}
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

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

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

package main

import (
	"fmt"
	"math"
)

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

func power(a int) (int) {
	if a < 10 {
		return a
	}
	//fmt.Println(a)

	order := int(math.Floor(math.Log10(float64(a))))
	addition := max(a / int(math.Pow10(order)) - 1, 1)
	top := int(math.Pow(9.0, float64(order))) * addition

	//fmt.Println("Versus", top, "order", order, "addition", addition)
	return max(top, (a / int(math.Pow10(order))) * power(a % int(math.Pow10(order))))
}

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

package main

import (
	"fmt"
)

func reverseInts(input []int) []int {
	if len(input) == 0 {
		return input
	}
	return append(reverseInts(input[1:]), input[0])
}

func main(){
	var n int
	fmt.Scan(&n)
	var list []int
	ans := 1;
	for ;;{
		if n == 0{
			break
		}
		list=append(list, n % 10)
		ans *= n % 10
		n /= 10
	}

	for index, each := range list{
		tmp := 1
		if each > 0{
			for i := index - 1; i >= 0; i--{
				tmp *= 9
			}
			for i := index + 1; i < len(list); i++{
				tmp *= list[i]
			}
			//fmt.Println(index, each)
			if each == 1 && index == len(list) - 1{

			}else{
				tmp *= each - 1
			}
			if tmp > ans{
				ans = tmp
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	ch := string("")
	fmt.Scanf("%s", &ch)
	num := []byte(ch)
	s1 := uint64(1)
	for _, char := range num {
		s, _ := strconv.ParseUint(string(char), 10, 64)
		s1 *= s
	}
	for i, char := range num {
		if char == '0' {
			break
		}
		num1 := []byte{}
		num1 = num
		num1[i] = num[i] - 1
		s2 := uint64(1)
		for j, char := range num1 {
			var number uint64
			if j <= i {
				number, _ = strconv.ParseUint(string(char), 10, 64)
				if number == 0 {
					number = 1
				}
			} else {
				number = 9
			}
			s2 *= number
		}
		if s2 > s1 {
			s1 = s2
		}
	}
	println(s1)

}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func main() {
	defer writer.Flush()
	ch := string("")
	scanf("%s", &ch)
	num := []byte(ch)
	s1 := uint64(1)
	for _, char := range num {
		s, _ := strconv.ParseUint(string(char), 10, 64)
		s1 *= s
	}
	for i, char := range num {
		if char == '0' {
			break
		}
		num1 := []byte{}
		num1 = num
		num1[i] = num[i] - 1
		s2 := uint64(1)
		for j, char := range num1 {
			var number uint64
			if j <= i {
				number, _ = strconv.ParseUint(string(char), 10, 64)
				if number == 0 {
					number = 1
				}
			} else {
				number = 9
			}
			s2 *= number
		}
		if s2 > s1 {
			s1 = s2
		}
	}
	printf("%d\n", s1)

}

package main

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

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

	var n int64
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]int64, 20)
	len := 0
	for n > 0 {
		mat[len] = n % int64(10)
		n /= 10
		len++
	}
	for i := len - 1; i >= 0; i-- {
		if mat[i] == 0 {
			for j := i + 1; j < len; j++ {
				mat[j]--
				if mat[j] > 0 || (mat[j] == 0 && j == len-1) {
					for k := j - 1; k >= 0; k-- {
						mat[k] = 9
					}
					break
				}
			}
			break
		}
	}
	//fmt.Printf("%v\n",mat)
	for i := len; i >= 0; i-- {
		if mat[i] > 0 {
			len = i + 1
			break
		}
	}
	var le int64 = 1
	var ans int64 = 1
	var tmp int64 = 1
	for i := 0; i < len; i++ {
		ans *= mat[i]
		le *= 9
	}
	//fmt.Printf("-%d len=%d %v\n",ans,len,mat)

	for i:=len-1;i>=0;i--{
		le/=9
		if mat[i] > 1{
			if tmp*(mat[i]-1)*le > ans{
				ans=tmp*(mat[i]-1)*le
			}
		}
		tmp *= mat[i]
	}
	fmt.Printf("%d\n",ans)
}