package main

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

func Init() {
}

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

	d := Abs(A - B)
	lo := d >> 1
	hi := d - lo
	io.Println(Tiredness(lo) + Tiredness(hi))
}

func Tiredness(k int) int {
  return k * (k + 1) / 2
}

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

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)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import "fmt"

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

	lo, hi := int64(0), n*m
	largest := int64(0)
	for lo <= hi {
		mid := (lo + hi) / 2

		count := int64(0)
		for i := int64(1); i <= n; i++ {
			x := min(m, mid/i)
			count += x
		}

		if count < k {
			largest = mid
			lo = mid + 1
		} else {
			hi = mid - 1
		}
	}

	fmt.Printf("%d\n", largest+1)
}

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


package main

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

// func deb(T ...interface{}) {
// 	if len(T) == 0 {
// 		return
// 	}
// 	fmt.Print
// }

func debug(T ...interface{}) {
	fmt.Println(T...)
}

const N = 505
const M = 130000

var p [N]int
var dp [2][2 * M]int64
var f [N]int64

var in = bufio.NewReader(os.Stdin)

func solve(t int) {
	var n int
	var mod int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &mod)
	f[0] = int64(1)
	for i := 1; i <= n; i++ {
		f[i] = (f[i-1] * int64(n-i+1)) % mod
	}
	dp[n&1][M] = 1
	ans := int64(0)
	for i := n; i > 1; i-- {
		i1 := (i & 1)
		i2 := i1 ^ 1
		for cd := 0; cd < 2*M; cd++ {
			dp[i2][cd] = 0
		}
		for cd := 0; cd < 2*M; cd++ {
			k := n - i + 1
			if dp[i1][cd] > 0 {
				// debug(i, cd-M, dp[i1][cd])
				for d := -k; d <= k; d++ {
					dd := d
					if dd < 0 {
						dd = -dd
					}
					val := (dp[i1][cd] * int64(k+1-dd)) % mod
					dp[i2][cd+d] = (dp[i2][cd+d] + val) % mod
					if d < 0 && cd+d > M {
						val1 := (val * f[i-2]) % mod
						ans += val1
						if ans >= mod {
							ans -= mod
						}
						// debug(i, d, cd-M, val1)
					}
				}
			}
		}
	}
	// for cd := 0; cd < 2*M; cd++ {
	// 	if dp[1][cd] > 0 {
	// 		debug(1, cd-M, dp[1][cd])
	// 	}
	// }
	fmt.Println(ans)
}

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


package main

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

        "sort"
)

func main() {
	n, m := readInt2()
	a := readInts()

        sort.Sort(sort.IntSlice(a))

	for days := 1; days <= n; days++ {
		for start := 0; start < n; start++ {
			s := 0
			for i := 0; i < n-start; i++ {
				if a[start+i] > i/days {
					s += a[start+i] - i/days
					if s >= m {
						fmt.Println(days)
						return
					}
				}
			}
		}
	}
	fmt.Println(-1)
}

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

func readLine() string {
	s, _ := stdin.ReadString('\n')
	return s
}

func readInts() (r []int) {
	reader := strings.NewReader(readLine())
	for {
		var x int
		_, err := fmt.Fscan(reader, &x)
		if err != nil {
			break
		}
		r = append(r, x)
	}
	return
}

func readInt2() (int, int) {
	a := readInts()
	return a[0], a[1]
}


package main

import (
	"fmt"
	"sort"
)

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

func main()  {
	var n, m int
	fmt.Scanln(&n,&m)
	//fmt.Println(n,m)
	a := make([]int, n)
	b := make([]int, m)
	for i := 0; i < n; i++{
		if(i < n-1){
			fmt.Scanf("%d",&a[i])
		} else {
			fmt.Scanf("%d\n",&a[i])
		}
		//fmt.Printf("%d\n",a[i])
	}
	for i := 0; i < m; i++{
		if(i < m-1){
			fmt.Scanf("%d",&b[i])
		} else {
			fmt.Scanf("%d\n",&b[i])
		}
		//fmt.Printf("%d\n",b[i])
	}
	sort.Ints(a)
	sort.Ints(b)
	var ans int = 99999999
	for i := 0; i < n; i++{
		for j := 0; j < m; j++{
			if a[i] == b[j]{
				ans = min(ans,a[i])
			}
		}
	}
	if(ans == 99999999){
		ans = min(a[0] * 10 + b[0], b[0] * 10 + a[0])
	}
	fmt.Println(ans)
}


package main

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

func solve() {
	n := readInt()
	m := readInt()

	ns := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		ns[readInt()] = true
	}

	ms := make(map[int]bool, m)
	for i := 0; i < m; i++ {
		ms[readInt()] = true
	}

	for i := 1; i <= 9; i++ {
		if ms[i] && ns[i] {
			fmt.Println(i)
			return
		}
	}
	for i := 10; i <= 99; i++ {
		if ms[i/10] && ns[i%10] {
			fmt.Println(i)
			return
		}
		if ns[i/10] && ms[i%10] {
			fmt.Println(i)
			return
		}
	}
}

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


package main

import (
	"fmt"
)

func swap(a *int, b *int) {
	temp := *a
	*a = *b
	*b = temp
}

type Cube struct {
	elements [24]int
}

type Turn struct {
	square [4]int
	wall   [8]int
}

func NewTurn(cube [4]int, wall [8]int) Turn {
	for index := 0; index < 4; index++ {
		cube[index]--
	}

	for index := 0; index < 8; index++ {
		wall[index]--
	}

	return Turn{cube, wall}
}

func (cube *Cube) RotateLeft(turn Turn) {
	square := turn.square
	wall := turn.wall

	first := cube.elements[square[0]]
	for index := 0; index < 3; index++ {
		cube.elements[square[index]] = cube.elements[square[index+1]]
	}
	cube.elements[square[3]] = first

	for iteration := 0; iteration < 2; iteration++ {
		first := cube.elements[wall[0]]
		for index := 0; index < 7; index++ {
			cube.elements[wall[index]] = cube.elements[wall[index+1]]
		}
		cube.elements[wall[7]] = first
	}
}

func (cube *Cube) RotateRight(turn Turn) {
	square := turn.square
	wall := turn.wall

	last := cube.elements[square[3]]
	for index := 3; index > 0; index-- {
		cube.elements[square[index]] = cube.elements[square[index-1]]
	}
	cube.elements[square[0]] = last

	for iteration := 0; iteration < 2; iteration++ {
		last := cube.elements[wall[7]]
		for index := 7; index > 0; index-- {
			cube.elements[wall[index]] = cube.elements[wall[index-1]]
		}
		cube.elements[wall[0]] = last
	}
}

func (cube *Cube) IsPerfect() bool {
	perfect := true

	for side := 0; side < 6 && perfect; side++ {
		for index := 0; index < 4 && perfect; index++ {
			if cube.elements[4*side+index] != cube.elements[4*side] {
				perfect = false
			}
		}
	}

	return perfect
}

func main() {
	var cube Cube
	for index := 0; index < 24; index++ {
		fmt.Scanf("%d", &cube.elements[index])
	}

	turns := []Turn{
		NewTurn([4]int{1, 2, 4, 3}, [8]int{22, 21, 18, 17, 6, 5, 14, 13}),
		NewTurn([4]int{5, 6, 8, 7}, [8]int{3, 4, 17, 19, 10, 9, 16, 14}),
		NewTurn([4]int{9, 10, 12, 11}, [8]int{7, 8, 19, 20, 23, 24, 15, 16}),
		NewTurn([4]int{13, 14, 16, 15}, [8]int{1, 3, 5, 7, 9, 11, 24, 23}),
		NewTurn([4]int{17, 18, 20, 19}, [8]int{4, 2, 21, 23, 12, 10, 8, 6}),
		NewTurn([4]int{21, 22, 24, 23}, [8]int{2, 1, 13, 15, 11, 12, 20, 18}),
	}

	can := false

	for _, turn := range turns {
		cube.RotateLeft(turn)

		if cube.IsPerfect() {
			can = true
		}

		cube.RotateRight(turn)
		cube.RotateRight(turn)

		if cube.IsPerfect() {
			can = true
		}

		cube.RotateLeft(turn)
	}

	if can {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


package main

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

func solve() {
	var data [24]int
	for i := 0; i < 24; i++ {
		data[i] = readInt()
	}
	if isFullSide(data, 3) && isFullSide(data, 4) {
		row0 := []int{1, 3, 5, 7, 9, 11, 20, 22}
		row1 := []int{0, 2, 4, 6, 8, 10, 23, 21}

		if check(data, row0, row1, 2) {
			fmt.Println("YES")
			return
		}
		if check(data, row0, row1, -2) {
			fmt.Println("YES")
			return
		}
	}
	if isFullSide(data, 0) && isFullSide(data, 2) {
		row0 := []int{12, 13, 4, 5, 16, 17, 20, 21}
		row1 := []int{14, 15, 6, 7, 18, 19, 22, 23}

		if check(data, row0, row1, 2) {
			fmt.Println("YES")
			return
		}
		if check(data, row0, row1, -2) {
			fmt.Println("YES")
			return
		}
	}
	if isFullSide(data, 1) && isFullSide(data, 5) {
		row0 := []int{8, 9, 18, 16, 3, 2, 13, 15}
		row1 := []int{10, 11, 19, 17, 1, 0, 12, 14}

		if check(data, row0, row1, 2) {
			fmt.Println("YES")
			return
		}
		if check(data, row0, row1, -2) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func check(data [24]int, row0, row1 []int, dir int) bool {
	for i := 0; i < len(row0); i++ {
		if data[row0[i]] != data[row1[(i+dir+len(row1))%len(row1)]] {
			return false
		}
	}
	return true
}

func isFullSide(data [24]int, side int) bool {
	color := data[side*4]
	for i := 0; i < 4; i++ {
		if data[side*4+i] != color {
			return false
		}
	}
	return true
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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


package main

import "fmt"

var x, k, A, B, res int64

func main()  {
	fmt.Scanf("%d\n%d\n%d\n%d", &x, &k, &A, &B)
	if k == 1 {
		res = (x - 1) * A
		x = 1
	}
	for x > 1 {
		if x % k != 0 {
			d := x % k;
			x -= d
			res += A * d
			if x == 0 {
				x = 1
				res -= A
			}
		} else {
			d := x / k;
			if B > (x - d) * A {
				res += (x - d) * A
			} else {
				res += B
			}
			x = d
		}
	}
	fmt.Println(res)
}


package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a, b string
	fmt.Scanln(&n, &m)
	fmt.Scan(&a, &b)
	same := make([]int, len(b))
	for k := range b {
		j := k
		for i := range a {
			if a[i] == b[j] {
				same[k]++
				j = (j + 1) % len(b)
			}
		}
	}
	j := 0
	for i := 0; i < n; i++ {
		j += same[j%len(b)]
	}
	fmt.Println(j / (m * len(b)))
}


package main

import (
	"fmt"
	"strings"
)

func main() {
	var k int
	fmt.Scanf("%d", &k)
	rows := []int{0,0,0,0}
	if k <= 4 {
		for i := 0; i < k; i++ {
			rows[i] = 1
		}
	} else {
		rows[2] = 1
		q := (k - 4) / 3
		r := (k - 4) % 3
		rows[0], rows[1], rows[3] = q + 1, q + 1, q + 1
		if r >= 1 {
			rows[0]++
		}
		if r >= 2 {
			rows[1]++
		}
	}
	fmt.Println("+------------------------+")
	fmt.Printf("|%s%s|D|)\n", strings.Repeat("O.", rows[0]), strings.Repeat("#.", 11 - rows[0]))
	fmt.Printf("|%s%s|.|\n", strings.Repeat("O.", rows[1]), strings.Repeat("#.", 11 - rows[1]))
	if rows[2] > 0 {
		fmt.Printf("|%s%s..|\n", strings.Repeat("O.", rows[2]), strings.Repeat("..", 11 - rows[2]))
	} else {
		fmt.Printf("|%s%s..|\n", strings.Repeat("#.", 1), strings.Repeat("..", 10))
	}
	fmt.Printf("|%s%s|.|)\n", strings.Repeat("O.", rows[3]), strings.Repeat("#.", 11 - rows[3]))
	fmt.Println("+------------------------+")
}


package main

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

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

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

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

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

    n := ReadInt32()
    s := make([]string, 4)

    s[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)\n"
    s[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|\n"
    s[0] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)\n"

    if n >= 3 {
        s[3] = "|O.......................|\n"
        n--
    } else {
        s[3] = "|#.......................|\n"
    }

    for i := 1; i <= n; i++ {
        s[i%3] = strings.Replace(s[i%3], "#", "O", 1)
    }

    writer.WriteString("+------------------------+\n")
    writer.WriteString(s[1])
    writer.WriteString(s[2])
    writer.WriteString(s[3])
    writer.WriteString(s[0])
    writer.WriteString("+------------------------+\n")
}


package main

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

func isSubsequence(s, t string) bool {
	if len(s) < len(t) {
		return false
	}

	i, j := 0, 0

	for j < len(t) && i < len(s) {
		if s[i] == t[j] {
			i++
			j++
		} else {
			i++
		}
	}

	return j == len(t)
}

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

func main() {
	var (
		s, t string
	)

	// file, err := os.Open("input.txt")
	// if err != nil {
	// 	panic(err)
	// }

	// reader := bufio.NewReader(file)

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%s\n", &t)

	if s == t {
		fmt.Println(0)
		return
	}

	var maxLen = -1
	for l := 0; l < len(s); l++ {
		for r := l; r < len(s); r++ {
			a := string(s[:l])
			b := string(s[r+1:])
			newS := strings.Join([]string{a, b}, "")

			if isSubsequence(newS, t) {
				maxLen = max(r-l+1, maxLen)
			}
		}
	}

	fmt.Println(maxLen)

}


package main

import (
	"fmt"
	"math"
)

func main() {
	var s, t string
	fmt.Scanln(&s)
	fmt.Scanln(&t)
	ans := 0
	for i := 0; i < len(s); i++{
		for j := 0; j < len(s); j++ {
			pos := 0
			for p := 0; p < len(s); p++ {
				if i <= p && p <= j{
					continue
				}
				if pos < len(t) && t[pos] == s[p]{
					pos++
				}
			}
			if pos == len(t){
				ans = int(math.Max(float64(ans), float64(j-i+1)))
			}
		}
	}
	fmt.Println(ans)
}


package main
import "fmt"
import "os"
import "bufio"

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

func main(){
    input := bufio.NewReader(os.Stdin)
    var s,t string
	fmt.Fscanf(input, "%s\n", &s)
    fmt.Fscanf(input, "%s\n", &t)

    n := len(s)
    m := len(t)

    l := make([]int, m)
    r := make([]int, m)

    pos := 0
    for i:=0; i<m; i++ {
        for ; t[i]!=s[pos]; pos++ {
        }
        l[i] = pos
        pos++
    }
    pos = n-1
    for i:=m-1; i>=0; i-- {
        for ; t[i]!=s[pos]; pos-- {
        }
        r[i] = pos
        pos--
    }

    /*
    for i:=0; i<m; i++ {
        fmt.Printf("%d %d\n", l[i],r[i])
    }
    */

    ans := max(n-1-l[m-1], r[0])
    for i:=0; i<m-1; i++ {
        ans = max(ans, r[i+1]-l[i]-1)
    }
    fmt.Println(ans)
}


package main

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

func main() {
	var first, second string
	stdio := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdio, "%s %s", &first, &second)
	idx := 1
	for i := 1; i < len(first); i++ {
		if first[i] < second[0] {
			idx++
		} else {
			break
		}
	}
	fmt.Println(first[:idx] + "" + second[:1])
}


package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b string
	fmt.Scanln(&a, &b)
	var str []string
	for i := 0; i < len(a); i++ {
		for j := 0; j < len(b); j++ {
			str = append(str, a[0:i+1]+b[0:j+1])
		}
	}
	sort.Strings(str)
	fmt.Println(str[0])
}


package main

import(
	"fmt"
	// "sort"
	"os"
	"bufio"
	// "math"
	// "strconv"
	// "strings"
)

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
}

func toInt(buf []byte) (o int) {
    for _, v := range buf {
        o = o*10 + int(v-'0')
    }
    return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var MD int64 = 1000000007
var f map[int]int

func deg(d int) int64 {
	if d == 0 {
		return 1
	}
	t := deg(d / 2)
	t *= t
	t %= MD
	if d % 2 == 1 {
		t = t * 2 % MD
	}
	return t
}

func calc(x int) int {
	if val, exists := f[x]; exists {
		return val
	}
	res := int(deg(x - 1))
	for i:= 2;i * i <= x; i++ {
		if x % i == 0 {
			first := i
			second := x / i
			res = res - calc(x / first)
			if res < 0 {
				res += 1000000007
			}
			if second != first {
				res = res - calc(x / second)
				if res < 0 {
					res += 1000000007
				}
			}
		}
	}
	res = res - 1
	if res < 0 {
		res += 1000000007
	}
	f[x] = res
	return res
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var x,y int
	f = make(map[int]int)
	f[1] = 1
	fmt.Fscanf(in, "%d %d\n", &x, &y)
	if y % x != 0 {
		fmt.Println(0)
		os.Exit(0)
	}
	y /= x
	fmt.Println(calc(y))
}


package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, total := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &total)
	t := make([]int, n)
	g := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &t[i], &g[i])
		sum += t[i]
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if t[i] < t[j] {
				t[i], t[j] = t[j], t[i]
				g[i], g[j] = g[j], g[i]
			}
		}
	}
	help(0, n, total, t, g, 0, 0, 0, 0, sum)
	fmt.Fprintf(out, "%d\n", ans)
	return
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}


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

  s := getS()
  n := len(s)
  counts := map[string]int{}
  for i := 0; i < n; i++ {
    if s[i] == '0' {
      continue
    }
    for j := i; j < n; j++ {
      if s[j] != '4' && s[j] != '7' {
        break
      }
      sub := s[i:j+1]
      counts[sub]++
    }
  }
  bestSub, bestCount := "-1", -1
  for sub, count := range counts {
    if count > bestCount || (count == bestCount && sub < bestSub) {
      bestSub, bestCount = sub, count
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", bestSub))
}


package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)
    four, seven := 0, 0
    for _, v := range s {
        if v == '4' {
            four++
        } else if v == '7' {
            seven++
        }
    }
    if (four+seven) == 0 {
        fmt.Println(-1)
    } else if four >= seven {
        fmt.Println(4)
    } else {
        fmt.Println(7)
    }
}


package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var s string
	n4,n7:=0,0
	fmt.Scan(&s)
	for _,ss:=range s {
		if ss=='4' {
			n4++
		}
		if ss=='7' {
			n7++
		}
	}
	if n4==0 && n7==0 {
		fmt.Println("-1")
	} else if n4>=n7 {
		fmt.Println("4")
	} else {
		fmt.Println("7")
	}
}


package main
import "fmt"

func main() {
	var pp, dd, x, y, t int64
	fmt.Scan(&pp, &dd)
	x=pp
	y=1
	for i:=0; i<=18; i++ {
		t=x%y
		if t==y-1 {
			pp=x
		} else if t<dd {
			pp=(x/y*y)-1
		} else {
			break
		}
		y=y*10
	}
	fmt.Println(pp)
}


package main

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

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

	var maxW, n, a, b int
	Fscan(in, &maxW, &n)
	n++
	weights := make([]int, n)
	values := make([]int, n)
	stocks := make([]int, n)
	Fscan(in, &weights[0], &values[0])
	stocks[0] = maxW / weights[0]
	for i := 1; i < n; i++ {
		Fscan(in, &a, &b, &weights[i], &values[i])
		stocks[i] = a / b
	}

	dp := make([]int, maxW+1)
	for i, v := range values {
		num, w := stocks[i], weights[i]
		for k := 1; num > 0; k <<= 1 {
			K := min(k, num)
			for j := maxW; j >= K*w; j-- {
				dp[j] = max(dp[j], dp[j-K*w]+K*v)
			}
			num -= K
		}
	}
	Fprint(out, dp[maxW])
}

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


package main

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

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

	var maxW, n, a, b int
	Fscan(in, &maxW, &n)
	n++
	weights := make([]int, n)
	values := make([]int, n)
	stocks := make([]int, n)
	Fscan(in, &weights[0], &values[0])
	stocks[0] = maxW / weights[0]
	for i := 1; i < n; i++ {
		Fscan(in, &a, &b, &weights[i], &values[i])
		stocks[i] = a / b
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, maxW+1)
	}
	for i, vi := range values {
		wi := weights[i]
		for j := range dp[i] {
			for k := 0; k <= stocks[i] && k*wi <= j; k++ {
				dp[i+1][j] = max(dp[i+1][j], dp[i][j-k*wi]+vi*k)
			}
		}
	}
	Fprint(_w, dp[n][maxW])
}

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


package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

func main() {
	defer w.Flush()
	for I(&n, " ") == nil {
		solve(n)
	}
}

var n, m, k int64

func solve(n int64) {
	I(&m, " ")
	I(&k, "\n")
	if n == m {
		O(1, "\n")
		return
	}
	if n == 1 {
		O(m, "\n")
		return
	}
	ans := int64(2)
	m -= n + 1
	h := int64(1)
	l := k - 1
	r := n - k
	for m > 0 {
		if l > 0 {
			h++
			l--
		}
		if r > 0 {
			h++
			r--
		}
		if r <= 0 && l <= 0 {
			ans += m / h
			m = 0
		} else {
			m -= h
			if m >= 0 {
				ans++
			}
		}
	}
	O(ans, "\n")
}


package main

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

func solve() {
	people := readInt()
	pillow := readInt()
	k := readInt()
	if people == 1 {
		fmt.Println(pillow)
		return
	}
	pillow -= people
	left := int64(k - 1)
	right := int64(people - k)
	best := 0
	lo := 0
	hi := pillow
	for lo <= hi && pillow > 0 {
		mi := lo + (hi-lo)/2
		rest := int64(pillow - mi)
		step := int64(mi - 1)
		var sum1 int64
		var sum2 int64
		if left > 0 && step > 0 {
			t := left
			if step < t {
				t = step
			}
			sum1 = int64(step-t+1+step) * t / 2
		}
		if right > 0 && step > 0 {
			t := right
			if step < t {
				t = step
			}
			sum2 = int64(step-t+1+step) * t / 2
		}
		if sum1+sum2 <= rest {
			best = mi
			lo = mi + 1
		} else {
			hi = mi - 1
		}
	}
	fmt.Println(best + 1)
}

var scanner *bufio.Scanner

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

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 "fmt"
import "sort"

func main() {
	var n, sum, ans, need int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
		v[i] *= 2
		sum += v[i]
	}
	need = 9 * n
	sort.Ints(v)
	for i := range v {
		if sum >= need {
			break
		}
		sum += 10 - v[i]
		ans++
	}
	fmt.Println(ans)
}


package main
import ("fmt")
func min(x, y int) int {
    if x < y {
        return x
    }
    return y
}

func main(){
	// your code goes here
	var n int
	var a int
	var b int
	var c int
	var res int
	res=0
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	if n>1{
	    res=min((n-1)*a,(n-1)*b)
	    res=min(res,a+(n-2)*c)
	    res=min(res,b+(n-2)*c)
	}
	fmt.Println(res)
}


package main

import (
	"fmt"
)

func distance(n,a,b,c int) int  {
	if(n==1) {
		return 0
	} else {
		if(a<b) {
			return a+distance(n-1,a,c,b)
		} else {
			return b+distance(n-1,b,c,a)
		}
	}
}

func main() {
	var n,a,b,c int
	fmt.Scanf("%d\n%d\n%d\n%d",&n,&a,&b,&c)
	total_distance:=distance(n,a,b,c)
	fmt.Print(total_distance)
}


package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextInt()
	b := sc.NextInt()
	c := sc.NextInt()

	if N == 1 {
		fmt.Println(0)
		return
	}

	if a < b {
		if a < c {
			fmt.Println(a * (N - 1))
		} else {
			fmt.Println(a + c*(N-2))
		}
	} else {
		if b < c {
			fmt.Println(b * (N - 1))
		} else {
			fmt.Println(b + c*(N-2))
		}
	}

}

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 (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func digit2pos(a int) (int, int) {
	if a == 0 {
		return 3, 1
	}
	a--
	return a / 3, a % 3
}

func legal(y, x int) bool {
	if y == 3 {
		return x == 1
	}
	return y >= 0 && y < 3 && x >= 0 && x < 3
}

// apply a→b like move to x
func move(x, a, b int) int {
	ay, ax := digit2pos(a)
	by, bx := digit2pos(b)

	py, px := digit2pos(x)

	py += by - ay
	px += bx - ax

	if !legal(py, px) {
		return -1
	}
	if py == 3 {
		return 0
	}
	return 1 + py*3 + px
}

func main() {
	n := getInt()
	w := getWord()

	var cnt int
	for f := 0; f <= 9; f++ {
		x := f
		for j := 1; j < n; j++ {
			x = move(x, int(w[j-1]-'0'), int(w[j]-'0'))
			if x == -1 {
				break
			}
		}
		if x != -1 {
			cnt++
		}
	}

	fmt.Println(YN(cnt == 1))
}

func YN(b bool) string {
	if b {
		return "YES"
	}
	return "NO"
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}


// 316A1
package main

import (
	"fmt"
)

func main() {
	var mark [333]bool
	var s string
	fmt.Scan(&s)
	var ans, m int64
	ans, m = 1, 10
	for i := 0; i < len(s); i++ {
		if s[i] == '?' {
			if i == 0 {
				ans *= 9
			} else {
				ans *= 10
			}
		} else if s[i] >= 'A' && s[i] <= 'J' && !mark[s[i]] {
			if i == 0 {
				ans *= 9
			} else {
				ans *= m
			}
			m--
			mark[s[i]] = true
		}
	}
	fmt.Println(ans)
}


package main

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

const (
	n = 1000000007
)

func sum(a, b int) int {
	s := a + b
	if s >= n {
		return s - n
	}
	return s
}

func mul(a, b int) int {
	return int(int64(a) * int64(b) % n)
}

func g0(a, b, h, w int) int {
	if a == 0 && b == 0 {
		return 1
	}
	var s int
	for x := h + 1; x <= a; x++ {
		s += g0(b, a - x, w, h)
	}
	return s
}

func f0(a, b int) int {
	if a == 0 || b == 0 {
		return 1
	}
	var s int
	for x := 1; x <= a; x++ {
		s += f0(b, a - x)
	}
	return s
}

func power(a, n int) int {
	r := 1
	for n > 0 {
		if (n & 1) != 0 {
			r = mul(r, a)
		}
		n /= 2
		if n > 0 {
			a = mul(a, a)
		}
	}
	return r
}

func inv(a int) int {
	return power(a, n - 2)
}

var facts []int
var ifacts []int

func cnk(n, k int) int {
	if k < 0 || k > n || n < 0 {
		return 0
	}
	return mul(mul(facts[n], ifacts[k]), ifacts[n-k])
}

func f1(a, b int) int {
	return sum(cnk(a + b - 1, a), cnk(a + b - 1, b))
}

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

func solve(a, b, h int) int {
	q := f1(a, b)
	h += 1
	if a == 0 {
		return 1
	}
	if b == 0 {
		if a >= h {
			return 1
		}
		return 0
	}
	p := 0
	for ka := 1; ka * h <= a; ka++ {
		for kb := max(1, ka - 1); kb <= ka + 1 && kb <= b; kb++ {
			c0 := cnk(b - 1, kb - 1)
			c1 := cnk(a - ka * (h - 1) - 1, ka - 1)
			// fmt.Printf("%d %d %d %d\n", ka, kb, c0, c1)
			d := mul(c0, c1)
			if ka == kb {
				p = sum(p, d)
			}
			p = sum(p, d)
		}
	}
	return mul(p, inv(q))
}

func main() {
	m := 200100
	facts = make([]int, m)
	ifacts = make([]int, m)
	facts[0] = 1
	for i := 1; i < m; i++ {
		facts[i] = mul(facts[i-1], i)
	}
	ifacts[m-1] = inv(facts[m-1])
	for i := m-2; i >= 0; i-- {
		ifacts[i] = mul(ifacts[i+1], i+1)
	}
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	a := cin.nextInt()
	b := cin.nextInt()
	h := cin.nextInt()
	fmt.Printf("%d\n", solve(b, a, h))
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}


package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	n := readi()
	k := readi()
	x := readi()
	_, a := readInts(n)

	var ans int
	for i := 0; i < n; i++ {
		if i < k {
			ans += x
		} else {
			ans += a[n-i-1]
		}
	}
	println(ans)
}


package main

import "fmt"

func main() {
	var n, k, x, a int
	fmt.Scan(&n, &k, &x)
	x *= k
	for ; k < n; k++ {
		fmt.Scan(&a)
		x += a
	}
	fmt.Println(x)
}


package main

import ("fmt")

func main(){
	var n, k, x int
	scan(&n, &k, &x)
	min := 0
	for i := 0; i < n; i++{
		var tm int
		scan(&tm)
		if i < n - k{
			min += tm
		}
	}
	min += k * x
	sout(min)
}

func scan(in ... interface{}){
	for _,k := range in{
		fmt.Scan(k)
	}
}

func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k, " ")
	}
	fmt.Println()
}


package main

import (
	"fmt"
	"math"
	"sort"
)

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

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

	var cuts []int

	odd := 0
	even := 0
	for i := 0; i < n; i++ {
		if odd > 0 && even > 0 && odd == even {
			cuts = append(cuts, (int)(math.Abs((float64)(list[i]-list[i-1]))))
			odd = 0
			even = 0
		}

		if list[i]%2 == 0 {
			even++
		} else {
			odd++
		}
	}

	sort.Ints(cuts)
	cost := 0
	count := 0
	for i := 0; i < len(cuts); i++ {
		cost += cuts[i]

		if cost > B {
			break
		}

		count++
	}

	fmt.Println(count)
}


package main

import
(
	"fmt"

)

func main() {

	var a int
	fmt.Scanln(&a)
	fmt.Print(((a+1)/2)*((a-(a+1)/2)+1))
	}


package main

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

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

func init() {
	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
}

type prop struct {
	hp, atk, def int
}

func main() {
	defer out.Flush()
	var (
		y, m prop
		h, a, d int
	)
	fmt.Fscan(in, &y.hp, &y.atk, &y.def)
	fmt.Fscan(in, &m.hp, &m.atk, &m.def)
	fmt.Fscan(in, &h, &a, &d)
	ans := 2000000000
	for ba := 0; ba <= 205; ba++ {
		for bd := 0; bd <= 205; bd++ {
			pr := ba * a + bd * d
			if pr >= ans {
				continue
			}
			dmg := y.atk + ba - m.def
			if dmg <= 0 {
				continue
			}
			live := (m.hp + dmg - 1) / dmg
			left := y.hp - live * (m.atk - y.def - bd)
			if left <= 0 {
				pr += (-left + 1) * h
			}
			if pr < ans {
				ans = pr
			}
		}
	}
	fmt.Fprintln(out, ans)
}


package main

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

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


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


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var n, m, k int64
	if scanner.Scan() {
		line := scanner.Text()

		fmt.Sscanf(line, "%d %d %d", &n, &m, &k)

		if n > m {
			n, m = m, n
		}

		if k < n {
			area1 := n * (m / (k + 1))
			area2 := n / (k + 1) * m
			if area1 < area2 {
				fmt.Println(area2)
			} else {
				fmt.Println(area1)
			}
		} else if n <= k && k < m {
			fmt.Println(n * (m / (k + 1)))
		} else if m <= k && k <= n+m-2 {
			fmt.Println((n / (k + 2 - m) * m / m))
		} else {
			fmt.Println(-1)
		}
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF894B(in io.Reader, out io.Writer) {
	const mod int64 = 1e9 + 7
	pow := func(x, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	var n, m, k int64
	Fscan(in, &n, &m, &k)
	if k == -1 && n&1 != m&1 {
		Fprint(out, 0)
	} else {
		Fprint(out, pow(pow(2, n-1), m-1))
	}
}

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


package main

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

func main() {

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

	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)

	scanner.Scan()
	k, _ := strconv.ParseInt(scanner.Text(), 10, 64)

	h := n / 2

	p := h / (k + 1)
	d := k * p

	fmt.Println(p, d, (n - p - d))
}


package main

import (
  "fmt"
  "math"
)

func main() {
  var n, k, diploma, certificates, noWinners int64
  fmt.Scanf("%d %d", &n, &k)

  diploma = int64(math.Floor(float64(n) / float64(2 * (k + 1))))
  certificates = k * diploma
  noWinners = n - (diploma + certificates)

  fmt.Printf("%d %d %d\n", diploma, certificates, noWinners)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var r, h float64
	fmt.Scan(&r, &h)
	h, count := h-r*math.Floor(h/r), 2*int(h/r)
	if h+r >= r*(math.Sqrt(3)/2+1) {
		count += 3
	} else if h >= r/2 {
		count += 2
	} else {
		count += 1
	}
	fmt.Println(count)
}


package main

import "fmt"

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

func abs(num int) int {
	return max(num, -num)
}

func main() {
	var r1, c1, r2, c2 int
	fmt.Scan(&r1, &c1, &r2, &c2)
	var rook, bishop, king int
	if r1 == r2 || c1 == c2 {
		rook = 1
	} else {
		rook = 2
	}
	if (r1+c1)%2 != (r2+c2)%2 {
		bishop = 0
	} else if r1+c1 == r2+c2 || r1-c1 == r2-c2 {
		bishop = 1
	} else {
		bishop = 2
	}
	king = max(abs(r1-r2), abs(c1-c2))
	fmt.Println(rook, bishop, king)
}


package main

import (
	"fmt"
	"strconv"
)

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

	as, ac, ai := to_binary_string(a)
	bs, bc, bi := to_binary_string(b)

	var c [3]int

	if len(as) < len(bs) {
		if ac == 0 {
			c[0] = 0
		} else {
			c[0] = len(as) - ai
		}
		for i := len(as) + 1; i <= len(bs)-1; i++ {
			c[1] += i - 1
		}
		if bc == 0 {
			c[2] = len(bs) - 1
		} else {
			c[2] = bi - 1
			if bc == 1 {
				c[2] += 1
			}
		}
	} else if len(as) == len(bs) {
		c[1] = bi - ai
		if bc == 1 {
			c[2] = 1
		}
	}

	fmt.Println(c[0] + c[1] + c[2])
}

func to_binary_string(n int64) (string, int, int) {
	out := ""
	zero_count := 0
	first_zero_index := -1
	for i := 0; n > 0; i++ {
		if n%2 == 0 {
			zero_count++
			first_zero_index = i
		}
		out = strconv.FormatInt(n%2, 10) + out
		n /= 2
	}
	return out, zero_count, len(out) - first_zero_index - 1
}


//  URL: http://codeforces.com/contest/96/problem/B
//  ~ Basic Implementation Problem, Brute Force. DP version can be found in
//  95B, where constraints are big (can't just generate all permutations).

package main

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

func isSuperLuckyNumber(n string) bool {
	return strings.Count(n, "4") == strings.Count(n, "7")
}

func _solve(s string, minLength int, maxLength int, queue []string, answers []string) string {
	elem := queue[0]
	if minLength <= len(elem) && len(elem) <= maxLength {
		elemInt, _ := strconv.Atoi(elem)
		sInt, _ := strconv.Atoi(s)
		if isSuperLuckyNumber(elem) && sInt <= elemInt {
			return elem
		}
	}
	if len(elem) <= maxLength {
		queue = append(queue, elem+"4")
		queue = append(queue, elem+"7")
		answers = append(answers, elem)
		return _solve(s, minLength, maxLength, queue[1:], answers)
	}
	return _solve(s, minLength, maxLength, queue[1:], answers)
}

func findMinAndMaxLength(s string) (int, int) {
	if len(s)%2 == 0 {
		return len(s), len(s) + 2
	}
	return len(s) + 1, len(s) + 1
}

func solve(s string) string {
	minLength, maxLength := findMinAndMaxLength(s)
	return _solve(s, minLength, maxLength, []string{"4", "7"}, []string{})
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var s string
	fmt.Fscanf(reader, "%s", &s)
	fmt.Fprintln(writer, solve(s))
}


package main

import (
	"fmt"
	"strconv"
)

//a,b <=n  && a+b==x
func count(n, x int64) (ans int64) {
	if n >= x {
		n = x - 1
	}
	ans = n - x/2
	if x%2 == 0 {
		ans++
	}
	if ans < 0 {
		ans = 0
	}
	return
}

func main() {
	var n int64
	fmt.Scan(&n)
	if n < 5 {
		fmt.Println(n * (n - 1) / 2)
		return
	}
	var ans int64
	var max9 int64 = 9
	for max9 < n {
		max9 = max9*10 + 9
	}
	if max9/2+1 <= n {
		fmt.Println(count(n, max9))
		return
	}
	smax9 := fmt.Sprint(max9)
	//for i := 0; i < len(smax9); i++ {
	tmp := []byte(smax9)
	for j := 0; j < 9; j++ {
		tmp[0] = byte(j) + '0'
		x, _ := strconv.ParseInt(string(tmp), 10, 64)
		ans += count(n, x)
		//fmt.Println(count(n, x), x)
		tmp[0] = '9'
	}
	//}
	fmt.Println(ans)
}


package main

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

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

func combination(a, b int64) int64 {
	b = min(b, a-b)
	nom, denom := int64(1), int64(1)
	for b > 0 {
		nom *= a
		denom *= b
		a -= 1
		b -= 1
	}

	return nom / denom
}

func pow(a, b int64) int64 {
	ret := int64(1)
	for b > 0 {
		ret *= a
		b -= 1
	}

	return ret
}

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

	n := readInts(r)[0]

	var res int64
	if n == 3 {
		res = int64(4*(n-1)) * pow(int64(3), int64(n-2))
	} else {
		res = int64(4*2*3) * pow(int64(4), int64(n-3))        // The n-block is in the beginning/end
		res += int64(4*(n-3)*3*3) * pow(int64(4), int64(n-4)) // The n-block has blocks to the left/right
	}

	fmt.Println(res)
}


package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"math/bits"
	"os"
)

func solve(n, x uint64) uint64 {
	if x > n {
		return 0
	}

	res := uint64(1)
	if x % 2 == 0 {
		res += solve(n, x + 1)
	}

	xlen := uint(bits.Len64(x))
	nlen := uint(bits.Len64(n))

	nx := x << (nlen - xlen)

	if nlen > xlen {
		res += (uint64(1) << (nlen - xlen)) - 2
	}

	if nx <= n && nlen > xlen {
		if n >> (nlen - xlen) == x {
			res += n - nx + 1
		} else {
			res += uint64(1) << (nlen - xlen)
		}
	}

	return res
}

func solveStupid(n, x uint64) uint64 {
	if x > n {
		return 0
	}

	res := uint64(1)
	if x % 2 == 0 {
		res += solveStupid(n, x + 1)
	}
	res += solveStupid(n, x * 2)

	return res
}

func main() {
	defer writer.Flush()

	n, k := uint64(NextInt64()), uint64(NextInt64())

	x := uint64(1)
	l := uint(0)
	for ; solve(n, x * 2) >= k; x *= 2 {
		l++
	}

	for i := uint(0); i < l; i++ {
		if solve(n, x + (uint64(1) << (l - i - 1))) >= k {
			x += uint64(1) << (l - i - 1)
		}
	}

	println(x)
}

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

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

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

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

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


package main

import (
	"fmt"
)

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

	fmt.Println(int64(n-2) * int64(n-2))
}


package main

import "fmt"

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

    r := int64(1)
    dif := int64(3)
    for i := 3; i < n; i++ {
        r += dif
        dif += 2
    }
    fmt.Println(r)
}


package main
import "fmt"
const MAX int64 = 1e7
const MOD int64 = 1e9+7
var isgood [MAX]bool
func Max(a, b int64) int64 {
	if (a < b) {
		return b
	}
	return a
}
func Init(a, b, n int64) {
	var k int64
	for k = 0; k < MAX; k++ { isgood[k] = true }
	for k = 1; k <= Max(a,b) * n; k++ {
		p := k
		for p > 0 {
			if p % 10 != a && p % 10 != b {
				isgood[k] = false
				break
			}
			p /= 10
		}
	}
}

func EE(a, b int64) int64 {
	var (
		r=a%b
		x0 int64=1
		y0 int64=0
		x1 int64=0
		y1 int64=1
		mod=b
	)
	for r > 0 {
		f:=a/b
		tx:=x0-f*x1
		ty:=y0-f*y1
		x0=x1
		y0=y1
		x1=tx
		y1=ty
		a=b
		b=r
		r=a%b
	}
	return (x1%mod+mod)%mod
}

func main() {
	var a,b,n int64
	fmt.Scanf("%d%d%d",&a,&b,&n)
	Init(a,b,n)
	var (
		choose int64=1
		x int64=0
		y int64
	)
	cnt := make(map[int64]int64)
	for x <= n {
		y=n-x
		s:=a*x+b*y
		if isgood[s] { cnt[s]=(cnt[s]+choose)%MOD }
		choose=((choose*(n-x))%MOD)*EE(x+1,MOD)%MOD
		x++
	}
	var ans int64 = 0
	for k,v := range cnt {
		if isgood[k] { ans = (ans + v) % MOD }
	}
	fmt.Println(ans)
}


package main

import "fmt"

func gcd(a int, b int, x *int, y *int) int {
    if a == 0 {
        *x, *y = 0, 1
        return b
    }
    var xx, yy int
    g := gcd(b%a, a, &xx, &yy)
    *x = yy - (b/a)*xx
    *y = xx
    return g
}

func normal(n int, mod *int) int {
    n %= (*mod)
    if n < 0 {
        n += (*mod)
    }
    return n
}

func inv(a int, mod *int) int {
    var x, y int
    gcd(a, *mod, &x, &y)
    return normal(x, mod)
}

func addmod(a, b int, mod *int) int {
    if a + b >= (*mod) {
        return a + b - (*mod)
    } else {
        return a + b
    }
}

func submod(a, b int, mod *int) int {
    if a - b < 0 {
        return a - b + (*mod)
    } else {
        return a - b
    }
}

func mulmod(a, b int, mod *int) int {
    return int((int64(a)*int64(b))%int64(*mod))
}

func divmod(a, b int, mod *int) int {
    return mulmod(a, inv(b, mod), mod)
}

func binpowmod(a, b int, mod *int) int {
    ans := 1
    for b > 0 {
        if b%2 == 1 {
            ans = mulmod(ans, a, mod)
        }
        a = mulmod(a, a, mod)
        b = b/2
    }
    return ans
}

func calc(y []int, x int, mod *int) int {
    ans := 0
    k := 1
    for j := 1; j < len(y); j++ {
        k = mulmod(k, normal(x - j, mod), mod)
        k = divmod(k, normal(0 - j, mod), mod)
    }
    for i := 0; i < len(y); i++ {
        ans = addmod(ans, mulmod(y[i], k, mod), mod)
        if (i + 1) >= len(y) {
            break
        }
        k = mulmod(k, divmod(normal(x - i, mod), normal(x - (i + 1), mod), mod), mod)
        k = mulmod(k, divmod(normal(i - (len(y) - 1), mod), normal(i + 1, mod), mod), mod)
    }
    return ans
}

func main() {
    var n, k int
    var mod int = 1000000007
    var y []int = make([]int, 0)
    s := 0
    y = append(y, s)
    fmt.Scanf("%d %d", &n, &k)
    for i := 0; i < k + 1; i++ {
        s = addmod(s, binpowmod(i + 1, k, &mod), &mod) //k-th powwer of (i+1)
        y = append(y, s)
    }
    if n < len(y) {
        fmt.Printf("%d", y[n])
    } else {
        p := calc(y, n, &mod)
        fmt.Printf("%d", p)
    }
}


package main

import (
	"fmt"
)

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

func main() {
	var x1, y1, x2, y2, x, y int
	fmt.Scanf("%v%v%v%v\n%v%v", &x1, &y1, &x2, &y2, &x, &y)
	dx := abs(x2 - x1)
	dy := abs(y2 - y1)
	result := "YES"
	if dx % x != 0 || dy % y != 0 || abs(dx / x - dy / y) % 2 == 1{
		result = "NO"
	}
	fmt.Println(result)
}


package main

import (
	"fmt"

)

func main() {
	var x1,x2,y1,y2,x,y int

	fmt.Scan(&x1,&y1,&x2,&y2,&x,&y)

	var ok bool

	if (x2-x1) % x == 0 && (y1-y2) % y ==0 {
		c1 := (x2-x1) / x
		c2 := (y2-y1) / y
		if (c1 - c2) % 2 == 0 {
			ok = true
		}

	} else {

	}

	if ok {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


package main

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

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

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

	res := 3
	if n > 1 {
		p := (n-1) % 3
		q := (n+2) / 3
		res = 4*q + 3*p / 2
	}

	fmt.Fprintln(w, res)
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	if b - a == c - b && c - b == d - c {
		fmt.Printf("%d", a + (b - a) * 4)
	} else if a != 0 && b != 0 && c != 0 && d != 0 && b * b == a * c && c * c == b * d && a != b {
		if d * d % c == 0 {
			fmt.Printf("%d", d * d / c)
		} else {
			fmt.Printf("42")
		}
	} else {
		fmt.Printf("42")
	}
}


package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	init := scanner.Text()
	heights := strings.Split(init, " ")

	cater, _ := strconv.Atoi(heights[0])
	apple, _ := strconv.Atoi(heights[1])

	scanner.Scan()
	input := scanner.Text()
	ins := strings.Split(input, " ")

	upS, _ := strconv.Atoi(ins[0])
	dS, _ := strconv.Atoi(ins[1])

	diffDay := (upS - dS) * 12
	days := 0
	// lets move for day1 first
	cater = (cater + 8*upS)
	if cater >= apple {
		fmt.Println(days)
		return
	}
	if dS >= upS {
		fmt.Println(-1)
		return
	}
	for {
		if cater >= apple {
			fmt.Println(days)
			return
		}

		days++
		cater += diffDay
	}

}


package main

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

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

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

	h1, h2 := nextInt(), nextInt()
	a, b := nextInt(), nextInt()

	h1 += a * 8

	if a <= b {
		if h1 < h2 {
			println(-1)
			return
		}
	}

	day := 0

	for h1 < h2 {
		h1 += (a - b) * 12
		day++
	}

	println(day)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


package main

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

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

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	var pa, pb [10][10]bool
	for i := 0;i < n;i ++ {
		var x, y int
		if i == n - 1 {
			fmt.Fscanf(reader, "%d %d\n", &x, &y)
		} else {
			fmt.Fscanf(reader, "%d %d ", &x, &y)
		}
		pa[x][y] = true
		pa[y][x] = true
	}
	for i := 0;i < m;i ++ {
		var x, y int
		if i == m - 1 {
			fmt.Fscanf(reader, "%d %d\n", &x, &y)
		} else {
			fmt.Fscanf(reader, "%d %d ", &x, &y)
		}
		pb[x][y] = true
		pb[y][x] = true
	}

	solution := make([]bool, 10)

	canDeduce := true
	for i := 1; i < 10;i ++ {
		for j := 1;j < 10;j ++ {
			if !pa[i][j] {
				continue
			}
			var b1, b2 bool
			for k := 1; k < 10;k ++ {
				if pb[i][k] && k != j {
					solution[i] = true
					b1 = true
				}
				if pb[k][j] && k != i {
					solution[j] = true
					b2 = true
				}
			}
			if b1 && b2 {
				canDeduce = false
			}
		}
	}
	for i := 1; i < 10;i ++ {
		for j := 1;j < 10;j ++ {
			if !pb[i][j] {
				continue
			}
			var b1, b2 bool
			for k := 1; k < 10;k ++ {
				if pa[i][k] && k != j {
					solution[i] = true
					b1 = true
				}
				if pa[k][j] && k != i {
					solution[j] = true
					b2 = true
				}
			}
			if b1 && b2 {
				canDeduce = false
			}
		}
	}

	ans, ansCount := 0, 0
	for i := 1;i < len(solution);i ++ {
		if solution[i] {
			ans, ansCount = i, ansCount + 1
		}
	}
	if ansCount == 1 {
		fmt.Printf("%d", ans)
	} else if canDeduce {
		fmt.Printf("0")
	} else {
		fmt.Printf("-1")
	}

}


package main

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

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

type Int64Slice []int64

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

var usr1 [20]int
var usr2 [20]int

var n, m int
var val [2][30]int

func guess(v int) int {
	ret := 0
	for i := 0; i < n; i++ {
		if v == val[0][i*2] || v==val[0][i*2+1] {
			for j := 0; j < m; j++ {
				if v == val[1][j*2] || v==val[1][j*2+1] {
          // fmt.Printf("v:%v   %v - %v\n",v,i,j)
					if
          (val[0][i*2] == val[1][j*2] && val[0][i*2+1] == val[1][j*2+1])|| (val[0][i*2] == val[1][j*2+1] && val[0][i*2+1] == val[1][j*2]){
					} else {
						if (usr1[i] == 0 || usr1[i] == v) && (usr2[j] == 0 || usr2[j] == v) {
							usr1[i] = v
							usr2[j] = v
							ret = v
						} else {
							return -1
						}
					}

				}
			}
		}
	}
	return ret
}

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

	n, m = ReadInt32(), ReadInt32()

	for i := 0; i < n; i++ {
		val[0][i*2] = ReadInt32()
		val[0][i*2+1] = ReadInt32()
	}
	for i := 0; i < m; i++ {
		val[1][i*2] = ReadInt32()
		val[1][i*2+1] = ReadInt32()
	}

	// 1 zu pei 1 -> res
	ans := -1
	for i := 1; i < 10; i++ {
		ret := guess(i)
		if ret == -1 {
			fmt.Printf("-1\n")
			return
		}
    if ret == 0 {
      continue
    }
		if ans == -1 {
			ans = ret
		} else {
			ans = 0
		}
	}
	fmt.Printf("%v\n", ans)

	// quan pei 1 -> 0

	// else -1

}

func Demo() {
	var n, m int64 = ReadInt64(), ReadInt64()
	PrintInt64s(n, m)
	writer.WriteByte('\n')
	slice := []int64{1, 2, 3, 4, 5}
	PrintInt64s(slice...)

	// sortDemo
	//slice := []int64{5, 3, 4, 2, 1}
	sort.Sort(Int64Slice(slice))

	//s := strconv.FormatBool(true)
	//s := strconv.FormatFloat(3.1415, 'E', -1, 64)
	//s := strconv.FormatInt(-42, 16)
	//s := strconv.FormatUint(42, 16)

}

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

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

func MinFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func MaxFloat64(a float64, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

func ReadInt64() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

func ReadFloat64() float64 {
	scanner.Scan()
	ans, _ := strconv.ParseFloat(scanner.Text(), 64)
	return ans
}

func PrintInt64s(ints ...int64) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(int(value)))
		writer.WriteByte(' ')
	}
}


package main

import "fmt"

func nextPermutation(a []int) bool {
    i := len(a)-1
    for (i > 0) && (a[i] <= a[i-1]) { i-- }
    if (i == 0) { return false }
    j := len(a)-1
    for a[j] <= a[i-1] { j-- }
    a[j], a[i-1] = a[i-1], a[j]
    j = len(a)-1
    for i < j {
        a[i], a[j] = a[j], a[i]
        i++; j--
    }
    return true
}

func main() {
    var g [5][5]int
    a := make([]int,5)
    for i := 0; i < 5; i++ {
        a[i] = i
        for j := 0; j < 5; j++ {
            fmt.Scan(&g[i][j])
        }
    }
    max := 0
    for {
        cnt := 0
        for i := 0; i < 4; i++ {
            for j := 0; (i+j) < 4; j += 2 {
                cnt += g[a[i+j]][a[i+j+1]]+g[a[i+j+1]][a[i+j]]
            }
        }
        if max < cnt { max = cnt }
        if !nextPermutation(a) { break }
    }
    fmt.Println(max)
}


package main

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

func verifyReallyBig(num int64, minDiff int64) (isReallyBig bool) {
	sum := int64(0)
	for n := num; n > 0; n /= 10 {
		sum += n % 10
	}
	diff := num - sum
	if diff >= minDiff {
		isReallyBig = true
	} else {
		isReallyBig = false
	}
	return
}

func searchMin(n int64, s int64) (min int64) {
	var left, right int64
	var isReallyBig bool
	lastMin := n + 1
	for left, right = 1, n/10 + 1; right > left; {
		min = (left + (right - left) / 2) * 10
		isReallyBig = verifyReallyBig(min, s)
		if isReallyBig {
			right = min / 10
			lastMin = min
		} else {
			left = min / 10 + 1
		}
	}
	return lastMin
}

func Solve(input io.Reader) (result string) {
	var n, s int64
	fmt.Fscan(input, &n, &s)
	return fmt.Sprintln(n - searchMin(n, s) + 1)
}

func main() {
	fmt.Print(Solve(os.Stdin))
}


package main

import (
	"fmt"
	"os"
)

var n int
var m int
var tmp int

func main() {
	fmt.Scan(&n)
	fmt.Scan(&m)
	suma := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		suma += tmp
	}

	ansa := 0
	for {
		if float64(m)-float64(suma)/float64((ansa+n)) <= float64(0.5) {
			fmt.Println(ansa)
			os.Exit(0)
		}
		suma += m
		ansa++

	}

}


package main

import "fmt"

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

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

	for passed(a, k) == false {
		a = append(a, k)
	}

	fmt.Printf("%d", len(a)-n)
}

func passed(a []int, k int) bool {
	avg := calcAvg(a)
	if avg+0.5 >= float64(k) {
		return true
	}
	return false
}

func calcAvg(a []int) float64 {
	total := 0
	for _, value := range a {
		total += value
	}
	return float64(total) / float64(len(a))
}


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

package main

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

type Position struct {
	X int
	Y int
}

type Node struct {
	Position Position
	Time     int
}

func getNeighbors(p Position) []Position {
	var validNeighbors []Position
	for i := -1; i <= 1; i++ {
		for j := -1; j <= 1; j++ {
			x := p.X + i
			y := p.Y + j
			if 0 <= x && x < 8 && 0 <= y && y < 8 {
				validNeighbors = append(validNeighbors, Position{X: x, Y: y})
			}
		}
	}
	return validNeighbors
}

func hasStatue(board [8]string, p Position, time int) bool {
	if 0 <= p.X-time && p.X-time < 8 {
		if string(board[p.X-time][p.Y]) == "S" {
			return true
		}
	}
	if 0 <= p.X-time-1 && p.X-time-1 < 8 {
		if string(board[p.X-time-1][p.Y]) == "S" {
			return true
		}
	}
	return false
}

func Solve(board [8]string) string {
	stack := []Node{{Position: Position{X: 7, Y: 0}, Time: 0}}
	for {
		currentNode := stack[len(stack)-1]
		stack = stack[:len(stack)-1]
		if currentNode.Time == 8 || currentNode.Position.X == 0 {
			return "WIN"
		}
		for _, neighbor := range getNeighbors(currentNode.Position) {
			if !hasStatue(board, neighbor, currentNode.Time) {
				stack = append(stack, Node{Position: neighbor, Time: currentNode.Time + 1})
			}
		}
		if len(stack) == 0 {
			break
		}
	}
	return "LOSE"
}

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

	var board [8]string
	for i := 0; i < 8; i++ {
		fmt.Fscanf(reader, "%s\n", &board[i])
	}
	fmt.Fprintf(writer, "%s\n", Solve(board))
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func vecset(a []int, v int) { la := len(a); for i:=0;i<la;i++ { a[i] = v } }
const MOD = 998244353
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M := gi(),gi(); mask := ia(10); for i:=0;i<M;i++ { u,v := gi(),gi(); mask[u] |= 1 << uint(v); mask[v] |= 1 << uint(u) }
	f := ia(520); g := ia(520); f[0] = 1
	for i:=1;i<=N;i++ {
		vecset(g,0)
		for j:=0;j<(1<<9);j++ {
			if f[j] != 0 {
				for k:=0;k<10;k++ {
					if (j >> uint(k)) & 1 == 0 {
						g[(j | ((1<<uint(k))-1)) & mask[k]] += f[j]
						g[(j | ((1<<uint(k))-1)) & mask[k]] %= MOD
					}
				}

			}
		}
		copy(f,g)
	}
	ans := 0
	for i:=0;i<(1<<9);i++ { ans += f[i]; ans %= MOD }
	fmt.Println(ans)
}


package main

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

func solve() {
    n := readInt()
    init := [2]int{}
    a, c := make([][2]int, n), make([]int, n)
    for i := 0; i < n; i++ {
        ch := readString()
        if ch == "B" {
            c[i] = 1
        }
        for j := range a[i] {
            v := readInt()
            if v > n {
                init[j] += v-n
                v = n
            }
            a[i][j] = v
        }
    }

    const inf = 100000000
    const mx = 1<<16
    const sz = 16*16+1
    mem := [mx][2][sz]int{}
    was := [mx]bool{}
    for i := range mem {
        for col := range mem[i] {
            diff := min(max(init[1-col]-init[col], 0), sz-1)
            for j := range mem[i][col] {
                val := inf
                if i == 0 && diff == j {
                    val = 0
                }
                mem[i][col][j] = val
            }
        }
    }

    ans := inf
    d := [mx][2]int{}
    q := make([]int, 1, 1<<16)
    q[0] = 0
    un := uint(n)
    was[0] = true
    for curI := 0; curI < len(q); curI++ {
        cur := q[curI]
        curD := d[cur]
        //fmt.Println("BFS", cur, curD)
        for col, u := range mem[cur] {
            for cnt, val := range u {
                if cur == (1<<un)-1 {
                    ans = min(ans, val)
                }

                if val >= inf {
                    continue
                }

                r, b := 0, 0
                if col == 0 {
                    r = cnt
                } else {
                    b = cnt
                }

                for bit := uint(0); bit < un; bit++ {
                    mask := 1 << bit
                    if cur & mask == 0 {
                        next := cur | mask
                        priceR, priceB := max(a[bit][0]-curD[0], 0), max(a[bit][1]-curD[1], 0)
                        //fmt.Println(" Price", priceR, priceB, val)
                        steps := max(priceR-r, priceB-b)
                        nextR, nextB := r+steps-priceR, b+steps-priceB
                        nextCol, nextVal := 0, min(nextR+nextB, sz-1)
                        if nextB > 0 {
                            nextCol = 1
                        }
                        mem[next][nextCol][nextVal] = min(mem[next][nextCol][nextVal], val+steps+1)

                        if !was[next] {
                            was[next] = true

                            nextD := curD
                            nextD[c[bit]]++
                            d[next] = nextD

                            q = append(q, next)
                        }
                    }
                }
            }
        }
    }

    ans += max(init[0], init[1])
    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 "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	ans := int(1e9)
	if y <= 0 && y <= x && x <= 1-y && -4*y < ans {ans = -4*y}
	if x > 0 && 1-x <= y && y <= x && 4*x-3 < ans {ans = 4*x-3}
	if y > 0 && -y <= x && x <= y && 4*y-2 < ans {ans = 4*y-2}
	if x < 0 && x <= y && y <= -x && -4*x-1 < ans {ans = -4*x-1}
	fmt.Println(ans)
}


package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

const MOD = 998244353
const LCM16 = 720720 // lcm(1, 2, 3, ..., 16)
const MAXK = 17

func add(a, b int) int {
	return (a + b) % MOD
}

func mul(a, b int) int {
	return int(int64(a) * int64(b) % MOD)
}

var dp [MAXK][LCM16]int
var pown [MAXK + 1]int

func main() {
	defer flush()

	var n, a0, k, ai int
	var genX, genY, genMod int64
	scan(&n, &a0, &genX, &genY, &k, &genMod)

	pown[0] = 1
	for i := 1; i <= MAXK; i++ {
		pown[i] = mul(pown[i-1], n)
	}

	ans := 0
	ai = a0
	for i := 0; i < n; i++ {
		dp[0][ai%LCM16]++
		ans = add(ans, mul(ai-ai%LCM16, mul(k, pown[k-1])))
		ai = int((int64(ai)*genX + genY) % genMod)
	}

	for i := 0; i+1 < k; i++ {
		for j := 0; j < LCM16; j++ {
			dp[i+1][j-j%(i+1)] = add(dp[i+1][j-j%(i+1)], dp[i][j])
			dp[i+1][j] = add(dp[i+1][j], mul(dp[i][j], n-1))
		}
	}

	for j := 1; j <= k; j++ {
		for i := 0; i < LCM16; i++ {
			ans = add(
				ans,
				mul(mul(dp[j-1][i], i), pown[k-j]),
			)
		}
	}

	printf("%d\n", ans)
}


package main

import (
	"fmt"
	"math/big"
)

var mem [1e6 + 1]*big.Int

func exp(k int) *big.Int {
	if mem[k] != nil {
		return mem[k]
	}
	t := exp(k / 2)
	mem[k] = new(big.Int).Mul(t, t)
	if k&1 != 0 {
		mem[k].Mul(mem[k], mem[1])
	}
	return mem[k]
}

func main() {
	var k, b, n, t int64
	fmt.Scan(&k, &b, &n, &t)
	if k == 1 {
		ans := (b*n + b - t) / b
		if ans < 0 {
			ans = 0
		}
		fmt.Println(ans)
		return
	}
	mem[0] = big.NewInt(1)
	mem[1] = big.NewInt(k)
	mul := big.NewInt(k - 1 + b)
	target := big.NewInt(t*(k-1) + b)
	for i := 0; ; i++ {
		if target.Cmp(new(big.Int).Mul(exp(i), mul)) < 0 {
			ans := int(n) - i + 1
			if ans < 0 {
				ans = 0
			}
			fmt.Println(ans)
			return
		}
	}
}


package main

import "fmt"

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

	answers := make([]int, numCases)

	for i := 0; i < numCases; i++ {
		var n, k, d int
		fmt.Scanf("%d %d %d\n", &n, &k, &d)

		_ = k // unused

		schedule := make([]int, n)
		for j := 0; j < n; j++ {
			if j == n-1 {
				fmt.Scanf("%d\n", &schedule[j])
			} else {
				fmt.Scanf("%d", &schedule[j])
			}
		}

		answers[i] = solveCase(schedule, d)
	}

	for _, a := range answers {
		fmt.Println(a)
	}
}

// solveCase solves single task case for:
// * schedule -- index - day, value - show id
// * days -- target number of days for subscription
func solveCase(schedule []int, days int) (numShows int) {
	shows := make(map[int]int)

	for i := 0; i < days; i++ {
		shows[schedule[i]]++
	}

	numShows = len(shows)

	for i := days; i < len(schedule); i++ {
		cnt := shows[schedule[i-days]]
		if cnt == 1 {
			delete(shows, schedule[i-days])
		} else {
			shows[schedule[i-days]]--
		}

		shows[schedule[i]]++

		if len(shows) < numShows {
			numShows = len(shows)
		}
	}

	return numShows
}


package main

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

var DEBUG = true

func main() {
	defer Flush()

	h := readi()
	w := readi()

	x := (h - 1) + (w - 1)
	ans := 4
	p := INF3
	for i := 0; i < x; i++ {
		ans = ans * 2 % p
	}
	println(ans)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

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

// Simple math functions

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

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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


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

  s := getS()
  n := len(s)
  max := 0
  seen := map[string]bool{}
  for i := 0; i < n; i++ {
    for j := i+1; j <= n; j++ {
      if seen[s[i:j]] && j-i > max {
        max = j-i
      }
      seen[s[i:j]] = true
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", max))
}