package main

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

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

var memo map[int64]int64

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

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

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


// 290A-mic
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	if n == 1 {
		fmt.Println("Washington")
	}
	if n == 2 {
		fmt.Println("Adams")
	}
	if n == 3 {
		fmt.Println("Jefferson")
	}
	if n == 4 {
		fmt.Println("Madison")
	}
	if n == 5 {
		fmt.Println("Monroe")
	}
	if n == 6 {
		fmt.Println("Adams")
	}
	if n == 7 {
		fmt.Println("Jackson")
	}
	if n == 8 {
		fmt.Println("Van Buren")
	}
	if n == 9 {
		fmt.Println("Harrison")
	}
	if n == 10 {
		fmt.Println("Tyler")
	}
	if n == 11 {
		fmt.Println("Polk")
	}
	if n == 12 {
		fmt.Println("Taylor")
	}
	if n == 13 {
		fmt.Println("Fillmore")
	}
	if n == 14 {
		fmt.Println("Pierce")
	}
	if n == 15 {
		fmt.Println("Buchanan")
	}
	if n == 16 {
		fmt.Println("Lincoln")
	}
	if n == 17 {
		fmt.Println("Johnson")
	}
	if n == 18 {
		fmt.Println("Grant")
	}
	if n == 19 {
		fmt.Println("Hayes")
	}
	if n == 20 {
		fmt.Println("Garfield")
	}
	if n == 21 {
		fmt.Println("Arthur")
	}
	if n == 22 {
		fmt.Println("Cleveland")
	}
	if n == 23 {
		fmt.Println("Harrison")
	}
	if n == 24 {
		fmt.Println("Cleveland")
	}
	if n == 25 {
		fmt.Println("McKinley")
	}
	if n == 26 {
		fmt.Println("Roosevelt")
	}
	if n == 27 {
		fmt.Println("Taft")
	}
	if n == 28 {
		fmt.Println("Wilson")
	}
	if n == 29 {
		fmt.Println("Harding")
	}
	if n == 30 {
		fmt.Println("Coolidge")
	}
	if n == 31 {
		fmt.Println("Hoover")
	}
	if n == 32 {
		fmt.Println("Roosevelt")
	}
	if n == 33 {
		fmt.Println("Truman")
	}
	if n == 34 {
		fmt.Println("Eisenhower")
	}
	if n == 35 {
		fmt.Println("Kennedy")
	}
	if n == 36 {
		fmt.Println("Johnson")
	}
	if n == 37 {
		fmt.Println("Nixon")
	}
	if n == 38 {
		fmt.Println("Ford")
	}
	if n == 39 {
		fmt.Println("Carter")
	}
	if n == 40 {
		fmt.Println("Reagan")
	}
}


// 290A
package main

import (
	"fmt"
)

func main() {
	var n int
	a := []string{"Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan"}
	fmt.Scan(&n)
	fmt.Print(a[n-1])
}


package main

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

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

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

	a1, a2, a3, a4, a5, a6 := nextInt(), nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	cnt := 0

	for i := 0; i < min(a1, a3); i++ {
		cnt += 1 + 2*a2
		a2++
	}

	cnt += a2 * 2 * (max(a1, a3) - min(a1, a3))

	for i := 0; i < min(a4, a6); i++ {
		cnt += 1 + 2*a5
		a5++
	}

	println(cnt)
}

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

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

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

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


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

package main

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

func s(x int) int {
	return x * x
}

func Solve(a1, a2, a3, a4, a5, a6 int) int {
	return s(a1+a2+a3) - s(a1) - s(a3) - s(a5)
}

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

	var a1, a2, a3, a4, a5, a6 int
	fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &a1, &a2, &a3, &a4, &a5, &a6)

	fmt.Fprintf(writer, "%d\n", Solve(a1, a2, a3, a4, a5, a6))
}


package main

import (
	"fmt"
	"os"
)

func main() {
	// f, _ := os.Open("input.txt")
	f := os.Stdin
	var a1, a2, a3, a4, a5, a6 int
	fmt.Fscanf(f, "%d %d %d %d %d %d", &a1, &a2, &a3, &a4, &a5, &a6)
	fmt.Println((a1+a2+a3)*(a1+a2+a3) - a1*a1 - a3*a3 - a5*a5)
}


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

package main

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

func Solve(n int64) int64 {
	if n == 1 {
		return 1
	} else if n == 2 {
		return 2
	} else if n == 3 {
		return 6
	}
	if n%2 == 1 {
		return n * (n - 1) * (n - 2)
	} else if n%2 == 0 && n%3 == 0 {
		return (n - 1) * (n - 2) * (n - 3)
	}
	return n * (n - 1) * (n - 3)
}

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

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

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


package main

import "fmt"

func GCD(a,b int64) int64 { if b == 0 { return a } else { return GCD(b,a%b) } }
func LCM(a,b int64) int64 { return (a/GCD(a,b))*b }

func main() {
    var n int64
    fmt.Scan(&n)
    ans := int64(1);
    if n <= 3 {
        for ; n > 0; n-- { ans *= n }

    } else if n%2 == 1 {
        for i := int64(0); i < 3; i++ {
            ans = LCM(ans,n-i)
        }
    } else {
        var s int64
        if n-50 > 0 { s = n-50 } else { s = 0 }
        for i := s; i <= n; i++ {
            for j := i+1; j <= n; j++ {
                for k := j+1; k <= n; k++ {
                    tmp := LCM(i,LCM(j,k))
                    if ans < tmp { ans = tmp }
                }
            }
        }
    }
    fmt.Println(ans)
}


package main

import "fmt"

func main() {
    var pass,code string
    fmt.Scan(&pass)
    digit := make(map[string]int)
    for i := 0; i < 10; i++ {
        fmt.Scan(&code)
        digit[code] = i
    }
    for i := 0; i < 8; i++ {
        a := pass[i*10:(i+1)*10]
        fmt.Print(digit[a])
    }
    fmt.Println()
}


package main

import (
	"fmt"
	"math"
)

var MOD int64 = 1000000007

func sum(x, y int64) int64 {
	if y == 1 {
		return x
	}

	if y == 0 {
		return 1
	}

	if y%2 == 1 {
		return sum(x, y-1) * x % MOD
	}

	tmp := sum(x, y/2)
	return tmp * tmp % MOD
}

func calc(a int64, b int64) int64 {
	var num int64

	num = 0
	for a > 0 {
		num = num + a/b
		a = a / b
	}

	return sum(b, num)
}

var set []int = make([]int, 0, 1000)

func prime(p int) {
	m := int(math.Sqrt(float64(p + 1)))
	for i := 2; i <= m && i <= p; i++ {
		if p%i == 0 {
			set = append(set, i)

			for p%i == 0 {
				p = p / i
			}
		}
	}

	if p != 1 {
		set = append(set, p)
	}
}

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

	prime(int(x))

	var ans int64 = 1
	for _, v := range set {
		ans = ans * calc(n, int64(v)) % MOD
	}

	fmt.Printf("%d\n", ans)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1228C(_r io.Reader, _w 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 x int
	var n int64
	Fscan(_r, &x, &n)
	primes := []int64{}
	for i := 2; i*i <= x; i++ {
		k := 0
		for ; x%i == 0; x /= i {
			k++
		}
		if k > 0 {
			primes = append(primes, int64(i))
		}
	}
	if x > 1 {
		primes = append(primes, int64(x))
	}
	ans := int64(1)
	for _, p := range primes {
		c := int64(0)
		for m := n; m > 0; m /= p {
			c += m / p
		}
		ans = ans * pow(p, c) % mod
	}
	Fprint(_w, ans)
}

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


package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

// 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 *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

	return a
}

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

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

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var x, n int64

func main() {
	x, n = ReadInt64_2()

	primes := TrialDivision(int(x))

	ans := int64(1)
	for p := range primes {
		prod := int64(1)
		for {
			if isOverflow(prod, int64(p)) {
				break
			}

			prod *= int64(p)
			if n < prod {
				break
			}
			num := int64(n / prod)

			tmp := modpow(int64(p), num, MOD)
			ans *= tmp
			ans %= MOD
		}
	}

	fmt.Println(ans % MOD)
}

func isOverflow(i, j int64) bool {
	return !(i < math.MaxInt64/j)
}

func modpow(a, e, m int64) int64 {
	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := modpow(a, halfE, m)
		return half * half % m
	}

	return a * modpow(a, e-1, m) % m
}

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int) map[int]int {
	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	p := map[int]int{}
	for i := 2; i*i <= n; i++ {
		exp := 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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


package main

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

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)
	if n%2 == 0 {
		fmt.Fprintln(out, "Mahmoud")
	} else {
		fmt.Fprintln(out, "Ehab")
	}
}


package main

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

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

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

func main() {
	// FLUSH STDOUT
	defer writer.Flush()

	var a int
	scanf("%d\n", &a)

	if a%2 == 1 {
		printf("Ehab\n")
	} else {
		printf("Mahmoud\n")
	}

}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF959A(in io.Reader, out io.Writer) {
	var n int
	if Fscan(in, &n);n&1>0 {
		Fprint(out, "Ehab")
	} else {
		Fprint(out, "Mahmoud")
	}
}

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


package main

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

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

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

	n := nextInt()
	a := make([]int, n)
	cntPair := 0

	for i := range a {
		a[i] = nextInt()
	}

	for i := range a {
		if a[i] == 1 {
			cntPair++
		} else if i > 0 && i < n-1 && a[i-1] == 1 && a[i+1] == 1 {
			cntPair++
		}
	}

	println(cntPair)
}

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

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

// Node -> node in Linked-List
type Node struct {
	D    int
	Next *Node
}

// Head -> head of Linked-List
type Head struct {
	Front *Node
	Back  *Node
	C     int
}

func (h *Head) createNode(i int) *Node {
	var n *Node = new(Node)
	n.D = i
	n.Next = nil
	h.C++
	return n
}

func (h *Head) solve() int {
	var c int
	h.Back = h.Front
	for i := 0; i < h.C-1; i++ {
		if (h.Back.Next.D - h.Back.D) == 1 {
			c++
		} else if (h.Back.Next.D - h.Back.D) == 2 {
			c += 2
		} else {
			c++
		}
		h.Back = h.Back.Next
	}
	if h.C > 0 {
		c++
	}

	return c
}

func (h *Head) free() {
	h.Back = h.Front
	for h.Back != nil {
		h.Front = h.Back.Next
		h.Back.D = 0
		h.Back.Next = nil
		h.Back = h.Front
	}
	h.C = 0
}

func main() {
	var head *Head = new(Head)
	var newNode *Node
	var scanner *bufio.Scanner
	var s string
	var count int = 0

	scanner = bufio.NewScanner(os.Stdin)
	head.Front = nil
	head.Back = nil
	head.C = 0
	// n
	scanner.Scan()

	// data
	scanner.Scan()
	s = regexp.MustCompile("\\s*").ReplaceAllString(scanner.Text(), "")
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			newNode = head.createNode(i + 1)
			if head.Front == nil {
				head.Front = newNode
				head.Back = newNode
			} else {
				head.Back.Next = newNode
				head.Back = newNode
			}
		}
	}

	head.Back = head.Front
	// fmt.Println("number of node(s):", head.C)
	// for head.Back != nil {
	// 	fmt.Printf("%d ", head.Back.D)
	// 	head.Back = head.Back.Next
	// }
	// fmt.Println()

	count = head.solve()

	fmt.Println(count)

	head.free()

	// fmt.Println("number of node(s):", head.C)
	// for head.Back != nil {
	// 	fmt.Printf("%d ", head.Back.D)
	// 	head.Back = head.Back.Next
	// }

}


package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

func pcheck(i bool) {
	if i {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

var debug = true

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	input := getLine2Ints(n)
	min, zero := 0, 2
	for i := 0; i < n; i++ {
		if input[i] == 0 {
			zero++
		} else {
			if zero <= 1 {
				min += zero + 1
			} else {
				min++
			}
			zero = 0
		}
	}
	printf("%d\n", min)
}


package main

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

var scanner *bufio.Scanner

func getI() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
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()

  a, b := getI(), getI()
  for {
    a++
    x, y := a, b
    for x != 0 {
      d := x%10
      if d == 4 || d == 7 {
        if d == y%10 {
          y /= 10
        } else {
          break
        }
      }
      x /= 10
    }
    if x == 0 && y == 0 {
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", a))
}


package main
import "fmt"

func main(){
    var n,m int
    fmt.Scan(&n,&m)
    var r,d,k int
    for {
        n++
        a1 := n;
        d = 0;
        k = 1;
        for a1 != 0{
            r = a1%10
            if r == 4 || r == 7{
                d = d + k*r
                k = k*10
            }
            a1 = a1/10;
        }
        if d == m {break}
    }
    fmt.Println(n);
}


package main

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

var scanner *bufio.Scanner

func getI() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
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()

  a, b := getI(), getI()
  for {
    a++
    x, y := a, b
    okay := true
    for x != 0 {
      d := x%10
      x /= 10
      if d == 4 || d == 7 {
        if d == y%10 {
          y /= 10
        } else {
          x = 0
          okay = false
        }
      }
    }
    if y == 0 && okay {
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", a))
}


package main

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

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

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

	n := nextInt()
	s := next()
	a := make([]int, 0, n)
	x := make([]int, 0, n*2)
	m := map[int][]int{4:[]int{3, 2, 2}, 6:[]int{5, 3}, 8:[]int{7, 2, 2, 2}, 9:[]int{7, 3, 3, 2}}

	for i := range s {
		if s[i] != '1' && s[i] != '0' {
			a = append(a, int(s[i] - '0'))
		}
	}

	for i := range a {
		if _, ok := m[a[i]]; ok {
			x = append(x, m[a[i]]...)
		} else {
			x = append(x, a[i])
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(x)))

	for i := range x {
		print(x[i])
	}

	println()
}

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

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

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var n int
    var used [20]int
    var s string
    fmt.Fscan(scanner, &n)
    fmt.Fscan(scanner, &s)

    for i := 0; i < n; i++ {
        a := s[i] - '0'
        if (a % 2 == 1 && a != 9) || a == 2 {
            used[a]++
        } else if a == 4 {
            used[2] += 2
            used[3]++
        } else if a == 6 {
            used[5]++
            used[3]++
        } else if a == 8 {
            used[2] += 3
            used[7]++
        } else if a == 9 {
            used[7]++
            used[3] += 2
            used[2]++
        }
    }
    for i := 9; i > 1; i-- {
        for used[i] > 0 {
            writer.WriteString(strconv.Itoa(i))
            used[i]--
        }
    }
    writer.Flush()
}


package main

import "fmt"

func main() {
	var n int
	var str string
	cnt := make([]int, 10)
	fmt.Scanln(&n)
	fmt.Scanln(&str)
	for _, ch := range str {
		switch ch {
		case '9':
			cnt[7] ++
			cnt[3] += 2
			cnt[2] ++
		case '8':
			cnt[7] ++
			cnt[2] += 3
		case '7':
			cnt[7] ++
		case '6':
			cnt[5] ++
			cnt[3] ++
		case '5':
			cnt[5] ++
		case '4':
			cnt[2] += 2
			cnt[3] ++
		case '3':
			cnt[3] ++
		case '2':
			cnt[2] ++
		}
	}
	for i := 7; i > 1; i-- {
		for j := 0; j <cnt[i]; j++ {
			fmt.Printf("%d", i)
		}
	}
	fmt.Println()
}


package main
import "fmt"

func main() {
	var(
		a1, a2, a3 int
		b1, b2, b3 int
		n int
		a, b int
		an, bn int
	)
	fmt.Scanln(&a1, &a2, &a3)
	fmt.Scanln(&b1, &b2, &b3)
	fmt.Scanln(&n)
	a = a1 + a2 + a3
	b = b1 + b2 + b3
	if a%5 == 0 {
		an = a/5
	}else {
		an = a/5 + 1
	}

	if b%10 == 0 {
		bn = b/10
	}else{
		bn = b/10 + 1
	}

	if (an+bn) <= n {
		fmt.Println("YES")
	}else {
		fmt.Println("NO")
	}
}


package main

import (
	"fmt"
)

func main() {
	var a, b [3]int64
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range b {
		fmt.Scan(&b[i])
	}
	var n int64
	fmt.Scan(&n)
	var sa, sb int64
	for i := range a {
		sa += a[i]
		sb += b[i]
	}
	var res string
	if (sa+4)/5+(sb+9)/10 <= n {
		res = "YES"
	} else {
		res = "NO"
	}
	fmt.Println(res)
}


package main

import "fmt"

func main() {
	var a1, a2, a3, b1, b2, b3 int
	fmt.Scan(&a1)
	fmt.Scan(&a2)
	fmt.Scan(&a3)
	fmt.Scan(&b1)
	fmt.Scan(&b2)
	fmt.Scan(&b3)
	var n int
	fmt.Scan(&n)
	a := a1 + a2 + a3
	b := b1 + b2 + b3

	cupsDone := false
	medalsDone := false
	for {
		if n < 0 {
			fmt.Println("NO")
			return
		}
		if b <= 0 {
			medalsDone = true
		}
		if medalsDone == false {
			b = b - 10
			n = n - 1
			continue
		}
		if a <= 0 {
			cupsDone = true
		}
		if cupsDone == false {
			a = a - 5
			n = n - 1
			continue
		}
		if cupsDone && medalsDone {
			break
		}
	}
	fmt.Println("YES")
}


package main

import (
	"fmt"
)

func main() {
	var t, s, x int
	fmt.Scan(&t, &s, &x)

	if t == x {
		fmt.Println("YES")
		return
	}
	for k := t + s; k <= x; k += s {
		if k == x || k + 1 == x {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}


package main

import "fmt"

func main() {
    var t, s, x int;
    fmt.Scanf("%d %d %d\n", &t, &s, &x);
    //fmt.Printf("??????????\n");
    delta := x - t;
    cnt := delta / s;
    re := delta % s;
    if delta < 0 {
        fmt.Println("NO");
    } else if re == 0 {
        fmt.Println("YES");
    } else if cnt > 0 && (re == 1) {
        fmt.Println("YES");
    } else {
        fmt.Println("NO");
    }
}


package main

import "fmt"

func main() {
    var t,s,x int
    fmt.Scan(&t, &s, &x)
    if x < t {
        fmt.Print("NO")
        return
    } else if x == t {
        fmt.Print("YES")
        return
    }
    x -= t
    if x < s {
        fmt.Print("NO")
        return
    }
    if x % s == 0 || x % s == 1 {
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }
}


package main
import ("fmt")

func min(x , y int)int {
	if (x<y){
		return x} else{
		return y
	}
}
func main(){
	var n int
	var h,m int
	fmt.Scanf("%d %d",&n,&h);
	//fmt.Scan(&h);
	fmt.Scan(&m);
	var a [55]int

	for i:=0;i<=n;i++{
		a[i] = h;
	}
	for i:=0 ; i<m;i++{
		var l, r int
	    var x int
	    fmt.Scan(&l)
	    fmt.Scan(&r)
	    fmt.Scan(&x)
	    for j:= l ;j<=r;j++{
	    	a[j] = min(a[j],x);
	    }
	}

	var ans int =0;
	for i:=1 ;i<=n;i++{
		ans = ans+ a[i]*a[i]
	}
	fmt.Print(ans)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n,h,m int
	fmt.Scan(&n)
	fmt.Scan(&h)
	fmt.Scan(&m)
	bl := make([]int,n + 1,n + 1)
	for i := 1 ; i <= n ;i++{
		bl[i] = 100
	}
	var x1,x2,x3 int
	for i := 0 ; i < m ;i ++{
		fmt.Scan(&x1)
		fmt.Scan(&x2)
		fmt.Scan(&x3)
		for i := x1; i <= x2  ; i++{
			bl[i] = min(bl[i],x3);
		}

	}
	var ans int = 0
	for i := 1 ;i  <=  n ;i ++{
		if(bl[i] == 100){
			ans += h * h
		}else{
			ans += bl[i] * bl[i];
		}
	}
	fmt.Println(ans)

}


package main
import ("fmt")

func min(x , y int)int {
	if (x<y){
		return x
	} else{
		return y}
}
func main(){
	var n int
	var h,m int
	fmt.Scan(&n);
	fmt.Scan(&h);
	fmt.Scan(&m);
	var a [55]int

	for i:=0;i<=n;i++{
		a[i] = h;
	}
	for i:=0 ; i<m;i++{
		var l, r int
	    var x int
	    fmt.Scan(&l)
	    fmt.Scan(&r)
	    fmt.Scan(&x)
	    for j:= l ;j<=r;j++{
	    	a[j] = min(a[j],x);
	    }
	}

	var ans int =0;
	for i:=1 ;i<=n;i++{
		ans = ans+ a[i]*a[i]
	}
	fmt.Print(ans)
}


package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    a, b := -1, -1
    for i:=0; i<n ; i++ {
        a = b
        fmt.Scan(&b)
    }
    //result time
    var canDetermine bool
    var updown string
    if b == 0 {
        canDetermine = true
        updown = "UP"
    } else if b == 15 {
        canDetermine = true
        updown = "DOWN"
    } else if a == -1 {

    } else if a >= b {
        canDetermine = true
        updown = "DOWN"
    } else {
        canDetermine = true
        updown = "UP"
    }
    if canDetermine {
        fmt.Print(updown)
    } else {
        fmt.Print(-1)
    }
}


package main

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

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

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

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

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

	var n int

	I(&n, "\n")
	d := make([]int, n)
	for i := range d {
		I(&d[i], " ")
	}
	if d[0] != 0 && d[0] != 15 && n == 1 {
		O("-1", "\n")
	} else {
		if d[n-1] == 0 {
			O("UP", "\n")
		} else if d[n-1] == 15 {
			O("DOWN", "\n")
		} else if d[n-1]-d[n-2] > 0 {
			O("UP", "\n")
		} else if d[n-1]-d[n-2] < 0 {
			O("DOWN", "\n")
		}
	}
}


package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	switch  {
	case A[len(A) - 1] == 15:
		fmt.Println("DOWN")
	case A[len(A) - 1] == 0:
		fmt.Println("UP")
	case N == 1:
		fmt.Println("-1")
	case A[len(A) - 2] < A[len(A) - 1]:
		fmt.Println("UP")
	default:
		fmt.Println("DOWN")
	}
}

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) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

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


// 106A-mic_rizal
package main

import (
    "fmt"
)

func main() {
    var a, b int
    var s, s1, s2 string
    fmt.Scan(&s)
    fmt.Scan(&s1, &s2)
    if s1[0] == 'T' {
        a = 10
    } else if s1[0] == 'J' {
        a = 11
    } else if s1[0] == 'Q' {
        a = 12
    } else if s1[0] == 'K' {
        a = 13
    } else if s1[0] == 'A' {
        a = 14
    } else {
        a = int(s1[0]) - 48
    }
    if s2[0] == 'T' {
        b = 10
    } else if s2[0] == 'J' {
        b = 11
    } else if s2[0] == 'Q' {
        b = 12
    } else if s2[0] == 'K' {
        b = 13
    } else if s2[0] == 'A' {
        b = 14
    } else {
        b = int(s2[0]) - 48
    }
    if s1[1] == s2[1] && a > b {
        fmt.Println("YES")
    } else if string(s1[1]) == s && string(s2[1]) != s {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}


package main
import (
    "fmt"
)
func main(){
    var n int
    fmt.Scan(&n)
    for i := 2; i < n; i++ {
        if n%i == 0 {
            fmt.Printf("%d%d\n",i,n/i)
            break
        }
    }

}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 2; i < n; i++ {
		if n%i == 0 {
			fmt.Printf("%d%d\n", i, n/i)
			return
		}
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1528B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	const mx int = 1e6
	d := [mx + 1]int{}
	for i := 1; i <= mx; i++ {
		for j := i; j <= mx; j += i {
			d[j]++
		}
	}

	var n int
	Fscan(in, &n)
	s := int64(d[n])
	for i, p2 := n-1, int64(1); i > 0; i-- {
		s = (s + p2*int64(d[i])) % mod
		p2 = p2 << 1 % mod
	}
	Fprint(out, s)
}

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


package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

const (
	MOD = 998244353
)

var (
	smlDiv []int
)

type fact struct {
	base, exp int
}

func cntFact(n int) int {
	rem := n
	facts := make([]fact, 0)
	for rem > 1 {
		curSmlDiv := smlDiv[rem]
		if len(facts) == 0 || facts[len(facts)-1].base != curSmlDiv {
			facts = append(facts, fact{base: curSmlDiv, exp: 1})
		} else {
			facts[len(facts)-1].exp++
		}

		rem /= curSmlDiv
	}

	result := int64(1)
	for _, fact := range facts {
		result = (result * int64(fact.exp+1)) % MOD
	}
	return int(result)
}

func pow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 1 {
		return int(int64(pow(a, b-1)) * int64(a) % MOD)
	} else {
		half := int64(pow(a, b/2))
		return int(half * half % MOD)
	}
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	N := sc.NextInt()

	smlDiv = InitInts1D(N+1, -1)
	smlDiv[1] = 1
	for i := 2; i <= N; i++ {
		if smlDiv[i] != -1 {
			continue
		}
		smlDiv[i] = i
		for j := int64(i) * int64(i); j <= int64(N); j += int64(i) {
			if smlDiv[j] == -1 {
				smlDiv[j] = i
			}
		}
	}

	ans := int64(0)
	for i := 1; i <= N; i++ {
		// fmt.Println(cntFact(i), pow(2, N-i-1))
		ans = (ans + int64(cntFact(i))*int64(pow(2, N-i-1))) % MOD
	}

	fmt.Fprintln(wr, ans)

}


package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func LITTLE(x int) int64 {
	var answer int64
	answer = answer + int64((x*x*x*x-x*x)/4) + int64(x*x*(x-1)*(x-1)/8) - int64(x*(x-1)*(x+x+1)*(x+x-1)/12)
	return answer
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(input, &n)
	if n == 1 {
		fmt.Println(1)
	}
	ARRAY := make([]int64, 0)
	ARRAY = append(ARRAY, 1)
	if n > 1 {
		var answer int64
		answer = 1

		for i := 2; i < n+1; i++ {
			qq := int64(NumberOfDivisors(i))
			answer = (answer*2 + qq - ARRAY[0]) % 998244353
			ARRAY[0] = qq

		}
		fmt.Println(answer)

	}
}


package main

import "fmt"

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

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

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

  var low, high int64
  if k % 2 == 0 {
    low = k / 2 - 1
    high = k / 2 + 1
  } else {
    low = k / 2
    high = k / 2 + 1
  }
  // fmt.Println(low, high)
  ret := min(max(0, low - 1 + 1), max(0, n - high + 1))
  fmt.Println(ret)
}


package main

import "fmt"

/*
var (
	a, b int
	s1,s2 string
)

func main() {
	fmt.Scan(&a,&b)
	fmt.Scanln(&s1)
	fmt.Scanln(&s2)
	if strings.Contains(s1,"*") {
		ss := strings.Split(s1,"*")
		l := len(ss[0])
		if strings.Contains(s2[:l],ss[0])&&strings.Contains(s2[l:],ss[1]){
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	} else {
		if strings.Contains(s1,s2) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}
*/

var (
	n,k int64
)

func main()  {
	fmt.Scan(&n,&k)
	if k>2*n-1{
		fmt.Println(0)
	} else {
		if k-1<n {
			fmt.Println((k-1)/2)
		}	else {
			fmt.Println(n-k/2+1/2)
		}
	}
}


package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt64(), sc.NextInt64()
	m := int64(0)
	if K%2 == 0 {
		m = K/2 - 1
	} else {
		m = K / 2
	}
	Q := max(0, min(m, N-(K-m-1)))
	fmt.Println(Q)

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

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

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 order(x, y *int64) {
	if *x < *y {
		*x, *y = *y, *x
	}
}

func main() {
	var a, b, sharps int64
	fmt.Scan(&a, &b)

	for b > 0 {
		sharps += a / b
		a, b = b, a%b
	}

	fmt.Println(sharps)
}


package main

import (
    "fmt"
    )

func calc(a, b uint64) uint64 {
    if a == 0 || b == 0 {
        return 0
    }

    if a < b {
        tmp := a
        a = b
        b = tmp
    }

    return a/b + calc(a%b, b)
}

func main() {
    var a, b uint64
    fmt.Scan(&a, &b)
    fmt.Println(calc(a, b))
}


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

  a, b := getI64(), getI64()
  count := int64(0)
  for b != 0 {
    count += a / b
    a, b = b, a % b
  }
  writer.WriteString(fmt.Sprintf("%d\n", count))
}


package main

import "fmt"

func main() {
    var cd string
    fmt.Scan(&cd)
    if cd == "a1" || cd == "a8" || cd == "h1" || cd == "h8" {
        fmt.Print(3)
        return
    }
    if cd[0] == 'a' || cd[0] == 'h' || cd[1] == '1' || cd[1] == '8' {
        fmt.Print(5)
        return
    }
    fmt.Print(8)
}


// http://codeforces.com/problemset/problem/710/A

package main

import (
	"fmt"
)

func main() {
	var c rune
	var d int

	fmt.Scanf("%c%d", &c, &d)

	k1 := c == 'a' || c == 'h'
	k2 := d == 1 || d == 8

	ans := 8
	if k1 {
		ans -= 3
	}

	if k2 {
		ans -= 3
	}

	if k1 && k2 {
		ans++
	}

	fmt.Println(ans)
}


package main

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

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

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

	steps := []rune{-1, 0, 1}
	move := 0
	s := []rune(next())

	s[0] -= 'a'
	s[1] -= '1'

	for i := range steps {
		x := s[0] + steps[i]

		if x >= 0 && x < 8 {
			for j := range steps {
				if steps[i] == 0 && steps[j] == 0 {
					continue
				}

				y := s[1] + steps[j]

				if y >= 0 && y < 8 {
					move++
				}
			}
		}
	}

	println(move)
}

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

func main() {
    var a string
    var b string
    var c int
    fmt.Scanln(&a)
    fmt.Scanln(&b)
    ai, _ := strconv.Atoi(a)

    digit := make([]int, 0, 10)
    for tmp:=ai; tmp>0; {
        digit = append(digit, tmp%10)
        tmp /= 10
    }
    sort.Ints(digit)

    zeros := 0
    c = 0
    for _, x := range digit {
        if x == 0 {
            zeros++
        }else {
            if zeros > 0 {
                c = x
                for zeros > 0 {
                    c *= 10
                    zeros--
                }
            }else {
                c *= 10
                c += x
            }
        }
    }

    ca := strconv.Itoa(c);
    if b == ca {
        fmt.Println("OK")
    }else {
        fmt.Println("WRONG_ANSWER")
    }
}


package main

import (
	"fmt"
	"strings"
	"os"
	"sort"
)

func com(A []string, B []string) bool{

    if(len(A) != len(B)){
        return false
    }

    for i :=0; i< len(A); i++{
    if A[i] != B[i]{
        return false
    }
    }

    return true

}

func main() {

var x,y string

fmt.Fscan(os.Stdin, &x)
fmt.Fscan(os.Stdin, &y)

A:= strings.Split(x, "")
B:= strings.Split(y, "")

sort.Strings(A)

for i :=0; i< len(A); i++{
    if A[i] != "0"{
        tmp := A[i]
        A[i] = A[0]
        A[0] = tmp
        break
    }
}

if com(A,B){
    fmt.Println ("OK")
} else {
    fmt.Println ("WRONG_ANSWER")
}

}


package main

import "fmt"

func equal(a, b []byte) bool {
	if len(a) != len(b) {
		return false
	}
	var n = len(a)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func main() {
	var input, answer []byte
	fmt.Scanf("%s\n%s", &input, &answer)
	var digits [10]int
	var n = len(input)
	for i := 0; i < n; i++ {
		digits[int(input[i]-'0')]++
	}
	var ans = make([]byte, 0)
	for i := 1; i < 10; i++ {
		if digits[i] > 0 {
			ans = append(ans, byte(i+'0'))
			digits[i]--
			break
		}
	}

	for i := 0; i < 10; i++ {
		for digits[i] > 0 {
			ans = append(ans, byte(i+'0'))
			digits[i]--
		}
	}

	if equal(ans, answer) {
		fmt.Println("OK")
	} else {
		fmt.Println("WRONG_ANSWER")
	}
}


package main

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

func check(num, i int64) int64 {
	var count, divider int64 = 0, 5

	for (i / divider) > 0 {
		count += i / divider
		divider *= 5
	}

	return count
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, _ := reader.ReadString('\n')
	var num, result, flag int64
	fmt.Sscanf(n, "%d", &num)
	var i int64 = 1

	for {

		result = check(num, i)

		if result > num {
			if flag == 0 {
				fmt.Print(0)
			}
			break
		} else if result == num {

			if flag == 0 {
				fmt.Println(5)
				flag = 1
			}

			fmt.Printf("%d ", i)
		}

		i++
	}

	fmt.Println()
}


package main

import "fmt"

func main() {
	n := 0
	fmt.Scanf("%d", &n)
	c := 0
	for i := 5; i <= 1e6; i += 5 {
		tmp := i
		for {
			if tmp%5 != 0 {
				break
			}
			tmp /= 5
			c++
		}
		if c < n {
			continue
		}
		if c == n {
			fmt.Println("5")
			for j := i; j < i+5; j++ {
				fmt.Print(j, " ")
			}
			break
		}
		if c > n {
			fmt.Println("0")
			break
		}
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
const mod int64 = 1e9 + 7

type matrix [][]int64

func newMatrix(n int) matrix {
	mat := make(matrix, n)
	for i := range mat {
		mat[i] = make([]int64, n)
	}
	return mat
}

func newMatrixI(n int) matrix {
	mat := make(matrix, n)
	for i := range mat {
		mat[i] = make([]int64, n)
		mat[i][i] = 1
	}
	return mat
}

func (a matrix) mul(b matrix) matrix {
	c := newMatrix(len(a))
	for i := range a {
		for j := range b[0] {
			for k, aik := range a[i] {
				c[i][j] += aik * b[k][j] % mod
			}
			c[i][j] %= mod
		}
	}
	return c
}

func (a matrix) pow(k int64) matrix {
	res := newMatrixI(len(a))
	for ; k > 0; k >>= 1 {
		if k&1 == 1 {
			res = res.mul(a)
		}
		a = a.mul(a)
	}
	return res
}

func CF1117D(in io.Reader, out io.Writer) {
	n, m := int64(0), 0
	Fscan(in, &n, &m)
	if n < int64(m) {
		Fprint(out, 1)
		return
	}
	a := newMatrix(m)
	a[0][0] = 1
	a[0][m-1] = 1
	for i := 1; i < m; i++ {
		a[i][i-1] = 1
	}
	Fprint(out, a.pow(n)[0][0])
}

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


package main

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

const Mod = 998244353

func main() {
	defer _w.Flush()
	n, x := int64(ReadInt()), int64(ReadInt())

	var dp [501][501]int64
	dp[n][0] = 1
	for i := int64(n); i >= 2; i-- {
		for j := int64(0); j < x; j++ {
			if dp[i][j] == 0 {
				continue
			}
			nj := Min(x, j+i-1)
			pow := int64(1)
			for k := i; k >= 0; k-- {
				dp[k][nj] += dp[i][j] * ModCombination(i, k) % Mod * pow
				dp[k][nj] %= Mod
				pow = pow * (nj - j) % Mod
			}
		}
	}
	ans := int64(0)
	for j := int64(0); j <= x; j++ {
		ans += dp[0][j]
		ans %= Mod
	}
	println(((ans % Mod) + Mod) % Mod)
}

func ModCombination(n, k int64) (ret int64) {
	if n < k {
		return int64(0)
	}
	for ret = int64(1); n > int64(0) || k > int64(0); n, k = n/Mod, k/Mod {
		ret = ret * fac[n%Mod] % Mod * finv[k%Mod] % Mod * finv[(n-k)%Mod] % Mod
	}
	return
}

const MAX = 500

var fac, finv, inv [MAX + 1]int64

func init() {
	fac[int64(0)], fac[int64(1)], finv[int64(0)], finv[int64(1)], inv[int64(1)] = int64(1), int64(1), int64(1), int64(1), int64(1)
	for i := int64(2); i <= MAX; i++ {
		fac[i], inv[i] = fac[i-int64(1)]*i%Mod, Mod-inv[Mod%i]*(Mod/i)%Mod
		finv[i] = finv[i-int64(1)] * inv[i] % Mod
	}
}

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

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func ReadString() (s string)   { fmt.Fscan(_r, &s); return }
func ReadInt() (i int)         { fmt.Fscan(_r, &i); return }
func print(a ...interface{})   { fmt.Fprint(_w, a...) }
func println(a ...interface{}) { fmt.Fprintln(_w, a...) }
func prints(s []int64)         { v := fmt.Sprint(s); println(v[int64(1) : int64(len(v))-int64(1)]) }


package main

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

const Mod = 998244353

func main() {
	defer _w.Flush()
	n, x := ReadInt(), ReadInt()

	var dp [501][501]int64
	dp[n][int64(0)] = int64(1)
	for i := n; i >= int64(2); i-- {
		for j := int64(0); j < x; j++ {
			if dp[i][j] == int64(0) {
				continue
			}
			nj := Min(x, j+i-int64(1))
			pow := int64(1)
			for k := i; k >= int64(0); k-- {
				dp[k][nj] += dp[i][j] * ModCombination(i, k) % Mod * pow
				dp[k][nj] %= Mod
				pow = pow * (nj - j) % Mod
			}
		}
	}
	ans := int64(0)
	for j := int64(0); j <= x; j++ {
		ans += dp[int64(0)][j]
		ans %= Mod
	}
	println(((ans % Mod) + Mod) % Mod)
}

func ModCombination(n, k int64) (ret int64) {
	if n < k {
		return int64(0)
	}
	for ret = int64(1); n > int64(0) || k > int64(0); n, k = n/Mod, k/Mod {
		ret = ret * fac[n%Mod] % Mod * finv[k%Mod] % Mod * finv[(n-k)%Mod] % Mod
	}
	return
}

const MAX = 500

var fac, finv, inv [MAX + 1]int64

func init() {
	fac[int64(0)], fac[int64(1)], finv[int64(0)], finv[int64(1)], inv[int64(1)] = int64(1), int64(1), int64(1), int64(1), int64(1)
	for i := int64(2); i <= MAX; i++ {
		fac[i], inv[i] = fac[i-int64(1)]*i%Mod, Mod-inv[Mod%i]*(Mod/i)%Mod
		finv[i] = finv[i-int64(1)] * inv[i] % Mod
	}
}

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

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func ReadString() (s string)   { fmt.Fscan(_r, &s); return }
func ReadInt() (i int64)       { fmt.Fscan(_r, &i); return }
func print(a ...interface{})   { fmt.Fprint(_w, a...) }
func println(a ...interface{}) { fmt.Fprintln(_w, a...) }
func prints(s []int64)         { v := fmt.Sprint(s); println(v[int64(1) : int64(len(v))-int64(1)]) }


package main

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

var n, x int

const MOD  = 998244353

const MAX = 500

var dp [MAX + 5][MAX + 5]int64

var bp [MAX + 5][MAX + 5]int64

var fact [MAX + 5]int64
var nk [MAX + 5][MAX + 5]int64

func main() {

	r := bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n, &x)

	ans := solve()
	fmt.Println(ans)
}

func solve() int64 {

	fact[1] = 1
	fact[0] = 1

	for j := 2; j <= MAX; j++ {
		fact[j] = (fact[j - 1] * int64(j)) % MOD
	}

	for i := 1; i <= MAX; i++ {
		for j := 1; j <= i; j++ {
			//i choose j
			//i!/(i - j)! * j!
			ij := fact[i - j]
			invIj := modInverse(ij, MOD)

			jj := fact[j]
			invJ := modInverse(jj, MOD)

			ii := fact[i]

			temp := ii * invIj % MOD

			nk[i][j] = temp * invJ % MOD
		}
	}

	for i := 1; i <= MAX; i++ {
		for j := 1; j <= MAX; j++ {
			bp[i][j] = binpow(int64(i), int64(j), MOD)
		}
	}

	for i := 1; i <= x; i++ {
		dp[0][i] = 1
	}

	for i := 1; i <= x; i++ {
		dp[2][i] = int64(i)
	}

	for i := 3; i <= n; i++ {
		for j := 1; j <= x; j++ {

			var lastSegLen int
			segs := j/(i - 1)
			r := j % (i - 1)
			if r != 0 {
				lastSegLen = r
				segs++
			} else {
				lastSegLen = i - 1
			}

			//dp[i][j]

			for k := 1; k <= i; k++ {
				for p := 1; p <= segs - 1; p++ {

					t := bp[i - 1][k]

					t2 := nk[i][k]

					t3 := (t * t2) % MOD

					temp := t3 * dp[i - k][j - (i - 1) * p]

					temp %= MOD

					dp[i][j] += temp
					dp[i][j] %= MOD
				}
			}

			dp[i][j] += binpow(int64(lastSegLen), int64(i), MOD)
			dp[i][j] %= MOD

		}
	}

	return dp[n][x]
}

func binpow(a int64, b int64, m int64) int64 {
	a %= m
	var res int64 = 1
	for ; b > 0;
	{
		if b & 1 == 1 {
			res = res * a % m
		}

		a = a * a % m
		b >>= 1
	}
	return res
}

func modInverse(a int64, m int64) int64 {
	var x, y int64
	g := gcdExtended(a, m, &x, &y)

	if g != 1 {
		panic( "Inverse doesn't exist")
	} else {

		// m is added to handle negative x
		res := (x % m + m) % m
		return res
	}
}

func gcdExtended(a int64, b int64, x *int64, y *int64) int64 {

	// Base Case
	if a == 0 {
		*x, *y = 0,1
		return b
	}

	// To store results of recursive call
	var x1, y1 int64
	gcd := gcdExtended(b%a, a, &x1, &y1);

	// Update x and y using results of recursive
	// call
	*x = y1 - (b/a)*x1;
	*y = x1
	return gcd
}


package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	k := scanInt(scanner)
	scanner.Scan()
	s := scanner.Text()
	n := len(s)
	pal := make([]int, n)
	for i, ch := range s {
		pal[i] = int(ch)
	}
	for i := (n-1)/2; i >= 0; i-- {
		j := n-1-i
		if pal[i] == pal[j] {
			continue
		}
		if pal[i] == '?' {
			pal[i] = pal[j]
		} else if pal[j] == '?' {
			pal[j] = pal[i]
		} else {
			writer.WriteString("IMPOSSIBLE\n")
			return
		}
	}
	seen := map[int]bool{}
	for i := 0; i < k; i++ {
		seen['a'+int(i)] = false
	}
	for _, ch := range pal {
		if ch != '?' {
			seen[ch] = true
		}
	}
	need := []int{}
	for ch, ok := range seen {
		if !ok {
			need = append(need, ch)
		}
	}
	sort.Ints(need)
	/*
	for _, ch := range pal {
		writer.WriteString(fmt.Sprintf("%c", ch))
	}
	writer.WriteString(fmt.Sprintf(" (k = %d)\n", k))
	writer.WriteString(fmt.Sprintf("need %d:", len(need)))
	for _, ch := range need {
		writer.WriteString(fmt.Sprintf(" %c", ch))
	}
	writer.WriteString("\n")
	*/
	nix := len(need)-1
	for i := (n-1)/2; i >= 0; i-- {
		if pal[i] != '?' {
			continue
		}
		j := n-1-i
		if nix == -1 {
			pal[i] = 'a'
			pal[j] = 'a'
		} else {
			pal[i] = need[nix]
			pal[j] = need[nix]
			nix--
		}
	}
	if nix != -1 {
		writer.WriteString("IMPOSSIBLE\n")
		return
	}
	for _, ch := range pal {
		writer.WriteString(fmt.Sprintf("%c", ch))
	}
	writer.WriteString("\n")
}


package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	const P int64 = 1e9 + 7
	solve := func() {
		var n int64
		var k int
		fmt.Fscan(in, &n, &k)
		var ans int64 = 1

		for i := 0; i < k; i++ {
			ans = ans * n % P
		}
		fmt.Fprintln(out, ans)

	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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


// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k int
		fmt.Fscan(reader, &n, &k)
		ans := int64(1)
		for i := 0; i < k; i++ {
			ans = ans * int64(n)
			ans = ans % 1000000007
		}
		write(f, ans, "\n")
	}
}


package main

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

const MOD = 1e9 + 7

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int64
		var k int
		fmt.Fscan(in, &n, &k)

		tot := int64(1)
		for i := 0; i < k; i++ {
			tot = (tot * n) % MOD
		}
		fmt.Fprintln(out, tot)
	}
}


package main

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

func readInt(reader *bufio.Scanner) int {
	var result int
	reader.Scan()
	result, _ = strconv.Atoi(reader.Text())
	return result
}

func main() {
	reader := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 2)
	reader.Buffer(buf, 501)
	reader.Split(bufio.ScanWords)
	x := readInt(reader)
	y := readInt(reader)
	z := readInt(reader)
	if z == 0 {
		if x > y {
			fmt.Println("+")
		} else if x < y {
			fmt.Println("-")
		} else {
			fmt.Println("0")
		}
	} else if x > y+z {
		fmt.Println("+")
	} else if y > x+z {
		fmt.Println("-")
	}else{
		fmt.Println("?")
	}
}


package main

import "fmt"

func main() {
	var a,b,c int
	fmt.Scanf("%d %d %d",&a,&b,&c)
	if a>b&&(b+c<a){
		fmt.Printf("+")
	} else if  a<b && (a+c)<b{
		fmt.Printf("-")
	} else if a==b&&c==0 {
		fmt.Printf("0")
	} else {
		fmt.Printf("?")
	}
}


// A. Nauuo and Votes
/*
Nauuo is a girl who loves writing comments.

One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.

It's known that there were 𝑥 persons who would upvote, 𝑦 persons who would downvote, and there were also another 𝑧 persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the 𝑥+𝑦+𝑧 people would vote exactly one time.

There are three different results: if there are more people upvote than downvote, the result will be "+"; if there are more people downvote than upvote, the result will be "-"; otherwise the result will be "0".

Because of the 𝑧 unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the 𝑧 persons vote, that the results are different in the two situations.

Tell Nauuo the result or report that the result is uncertain.

Input
The only line contains three integers 𝑥, 𝑦, 𝑧 (0≤𝑥,𝑦,𝑧≤100), corresponding to the number of persons who would upvote, downvote or unknown.

Output
If there is only one possible result, print the result : "+", "-" or "0".

Otherwise, print "?" to report that the result is uncertain.

Examples
Input
3 7 0

Output
-

Input
2 0 1

Output
+

Input
1 1 0

Output
0

Input
0 0 1

Output
?

Note
In the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is "-".

In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is "+".

In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is "0".

In the fourth example, if the only one person upvoted, the result would be "+", otherwise, the result would be "-". There are two possible results, so the result is uncertain.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(input), " ")
	x, _ := strconv.Atoi(arr[0])
	y, _ := strconv.Atoi(arr[1])
	z, _ := strconv.Atoi(arr[2])

	if x+z < y {
		fmt.Print("-")
	} else if y+z < x {
		fmt.Print("+")
	} else if x == y && z == 0 {
		fmt.Print("0")
	} else {
		fmt.Print("?")
	}
}


package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, p, k int
	fmt.Scanf("%d %d %d", &n, &p, &k)
	fmt.Println(pages(n, p, k))
}

func pages(n, p, k int) string {
	var result []string

	if p-k > 1 {
		result = append(result, "<<")
	}
	for i := p - k; i < p; i++ {
		if i > 0 {
			result = append(result, strconv.Itoa(i))
		}
	}

	result = append(result, "("+strconv.Itoa(p)+")")

	for i := p + 1; i <= p+k; i++ {
		if i <= n {
			result = append(result, strconv.Itoa(i))
		}
	}

	if p+k < n {
		result = append(result, ">>")
	}

	return strings.Join(result, " ")
}


package main

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

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

	var n, p, k int

	fmt.Fscanf(reader, "%d %d %d", &n, &p, &k)
	if p-k > 1 {
		fmt.Printf("<< ")
	}
	for i := p - k; i <= p+k; i++ {
		if i == p {
			fmt.Printf("(%d) ", i)
		} else if i >= 1 && i <= n {
			fmt.Printf("%d ", i)
		}
	}
	if p+k < n {
		fmt.Printf(">>")
	}
}


package main

import (
	"bytes"
	"fmt"
)

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

	var buffer bytes.Buffer

	if p - k > 1 {
		buffer.WriteString("<< ")
	}

	for i := p - k; i < p + k + 1; i++ {
		if (i < 1) || (i > n) {
			continue
		}

		if i == p {
			buffer.WriteString(fmt.Sprintf("(%d) ", i))
			continue
		}

		buffer.WriteString(fmt.Sprintf("%d ", i))
	}

	if p + k < n {
		buffer.WriteString(">>")
	}

	fmt.Println(buffer.String())
}


package main

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

var writer *bufio.Writer
var scanner *bufio.Scanner

func main() {
	ini()
	defer writer.Flush()

	n := scanInt()
	var a[6] int
	var b[6] int
	var c[6] int

	for i:=0; i<n; i++ {
		a[scanInt()]++
	}

	for i:=0; i<n; i++ {
		b[scanInt()]++
	}

	for i:=1; i<=5; i++ {
		c[i] += a[i] + b[i]
	}

	result := 0
	for i:=1; i<=5; i++ {
		if c[i] % 2 == 1 {
			writer.WriteString("-1")
			return
		}
		result += int(math.Abs(float64(a[i])-float64(b[i]))) / 2
	}

	writer.WriteString(strconv.Itoa(result / 2))
	return

}

func ini() {
	scanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	scanner.Split(bufio.ScanWords)
}

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

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


package main

import "fmt"

func main(){
	var n int;
	fmt.Scan (&n);
	a := make([]int, n);
	b := make([]int, n);
	counta := make([]int, 6);
	countb := make([]int, 6);
	for i := 0; i < n; i++{
		fmt.Scan(&a[i]);
		counta[a[i]]++;
	}
	for i:= 0; i < n; i++{
		fmt.Scan(&b[i]);
		countb[b[i]]++;
	}
	flag1 := 0;
	flag2 := 0;
	flag3 := true
	for i:= 1; i <=5; i++ {
		if (counta[i] + countb[i]) % 2 == 1{
			flag3 = false;
			break;
		} else if counta[i] == countb[i] {
			continue;
		} else if counta[i] < countb[i] {
			flag1 += countb[i] - counta[i]
		} else {
			flag2 += counta[i] - countb[i]
		}
	}
	if flag3 && flag2 == flag1 && flag2 % 2 != 1{
		fmt.Printf("%d\n", flag1/2);
	}else{
		fmt.Printf("-1\n");
	}
}


package main

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

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

const (
	//MaxScanTokenSize = 64 * 1024 // package default
	MaxScanTokenSize = 8 * 1024 * 1024 // 8M
)

func init() {
	scanner.Buffer(make([]byte, 0, MaxScanTokenSize), MaxScanTokenSize)
	scanner.Split(bufio.ScanWords)
}

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(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; 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 readFloat64() float64 {
	v, _ := strconv.ParseFloat(readString(), 64)
	return v
}

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

func main() {
	defer writer.Flush()

	n := readInt()
	a := readIntArray(n)
	b := readIntArray(n)

	count := make([]int, 6, 6)
	countA := make([]int, 6, 6)
	for i := 0; i < n; i++ {
		countA[a[i]]++
		count[a[i]]++
		count[b[i]]++
	}

	ans := 0
	for i := 1; i < 6; i++ {
		if count[i] % 2 != 0 {
			ans = -2
			break
		}
		diff := countA[i] - count[i] / 2
		if diff < 0 {
			diff = -diff
		}
		ans += diff
	}
	fmt.Fprintf(writer, "%d\n", ans / 2)
}


package main

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

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

func equal(x, y float64) bool {
	delta := x-y
	if (delta < 0) {
		delta *= -1
	}
	return delta <= 1e-6
}

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

	ax, ay := scanInt(scanner), scanInt(scanner)
	bx, by := scanInt(scanner), scanInt(scanner)
	cx, cy := scanInt(scanner), scanInt(scanner)
	x0, y0 := float64(bx-ax), float64(by-ay)
	l0 := math.Hypot(x0, y0)
	x0 /= l0
	y0 /= l0
	x1, y1 := float64(cx-bx), float64(cy-by)
	l1 := math.Hypot(x1, y1)
	x1 /= l1
	y1 /= l1
	if equal(x1, x0) && equal(y1, y0) {
		writer.WriteString("TOWARDS\n")
	} else if equal(x1, -y0) && equal(y1, x0) {
		writer.WriteString("LEFT\n")
	} else {
		writer.WriteString("RIGHT\n")
	}
}


package main

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

func scanInt64(scanner *bufio.Scanner) int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}

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

	ax, ay := scanInt64(scanner), scanInt64(scanner)
	bx, by := scanInt64(scanner), scanInt64(scanner)
	cx, cy := scanInt64(scanner), scanInt64(scanner)
	x0, y0 := bx-ax, by-ay
	x1, y1 := cx-bx, cy-by
	cross := x0*y1 - x1*y0
	if cross == 0 {
		writer.WriteString("TOWARDS\n")
	} else if cross > 0 {
		writer.WriteString("LEFT\n")
	} else {
		writer.WriteString("RIGHT\n")
	}
}


// 227A
package main

import (
	"fmt"
)

func main() {
	var a1, a2, b1, b2, c1, c2, x, y, z float64
	fmt.Scan(&a1, &a2)
	fmt.Scan(&b1, &b2)
	fmt.Scan(&c1, &c2)
	x = (b1 - a1) * (c2 - b2)
	y = (c1 - b1) * (b2 - a2)
	z = x - y
	if z == 0 {
		fmt.Print("TOWARDS")
	} else if z < 0 {
		fmt.Print("RIGHT")
	} else {
		fmt.Print("LEFT")
	}
}


package main

import "fmt"

func main() {
    var n int            // variabel n dengan jenis int
    fmt.Scan(&n)        // mengambil input
    if (n <= 10) || (n > 21) { // jika (n kurang dari sama dengan 10) atau (n lebih dari 21)
        fmt.Println(0)    // cetak 0
    } else if n == 20 {        // jika n sama dengan 20
        fmt.Println(15)        // cetak 15
    } else {
        fmt.Println(4)        // cetak 4
    }
}


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

func main() {
	var n int
	fmt.Scan(&n)
	if n<=10 || n>21 {
		fmt.Println("0")
	} else if n==20 {
		fmt.Println("15")
	} else {
		fmt.Println("4")
	}
}


// 104A-mic
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    if n == 20 {
        fmt.Println("15")
    } else if n <= 10 || n > 21 {
        fmt.Println("0")
    } else {
        fmt.Println("4")
    }
}


package main

import "fmt"

func minSlots(n int64) int {
	c := 1
	s := int64(7)
	for {
		if s >= n {
			return c
		}
		c ++;
		s *= 7
	}
}

var n, m int64
var slotN, slotM int
var ans = 0
var used = make([]bool, 7)
func cal(num []int) int64 {
	var result int64
	for _, n := range num {
		result = result * int64(7) + int64(n)
	}
	return result
}
func dfs(num []int) {
	if len(num) == slotN {
		if cal(num[:slotN]) >= n {
			return
		}
	} else if len(num) == slotN + slotM {
		if cal(num[slotN:]) < m {
			ans ++
		}
		return
	}
	for i, use := range used {
		if !use {
			used[i] = true
			dfs(append(num, i))
			used[i] = false
		}
	}
}

func main() {
	fmt.Scanf("%d %d", &n, &m)
	slotN = minSlots(n)
	slotM = minSlots(m)
	num := make([]int, 0, slotN + slotM + 1)
	dfs(num)
	fmt.Println(ans)
}


package main

import (
  "fmt"
)

func validate(arr []int64, nSlots int, n int64, m int64) bool {
  length := len(arr)
  for i:= 0; i < length; i++ {
    for j:= i+1; j < length; j++ {
      if arr[i] == arr[j] {
        return false
      }
    }
  }
  var num int64
  for i:= 0; i < nSlots; i++ {
    num = num*7+arr[i]
  }
  if num >= n {
    return false
  }
  num = 0
  for i:=nSlots; i < length; i++ {
    num = num*7+arr[i]
  }
  if num >= m {
    return false
  }
  //fmt.Println(arr)
  return true
}

func try(arr []int64, depth int, cnt *int) {
  length := len(arr)
  if depth == length {
    if validate(arr, nSlots, n, m) {
      (*cnt)++
    }
    return
  }
  for i:=0; i < 7; i++ {
    arr[depth] = int64(i)
    try(arr, depth+1, cnt)
  }
}
var n, m int64
var nSlots, mSlots int
func main() {
  fmt.Scan(&n, &m)
  for i:=n-1; i > 0; {
    nSlots++
    i /= 7
  }
  if nSlots == 0 {
    nSlots = 1
  }
  for i:=m-1; i > 0; {
    mSlots++
    i /= 7
  }
  if mSlots == 0 {
    mSlots = 1
  }

  if mSlots + nSlots > 7 || mSlots + nSlots == 0 {
    fmt.Println(0)
    return
  }

  //fmt.Println(nSlots, mSlots)
  var arr []int64 = make([]int64, nSlots+mSlots)

  var cnt int
  try(arr, 0, &cnt)
  fmt.Println(cnt)
  //testValidate()
}

func testValidate() {
  arr := make([]int64, 3)
  arr[0] = 0
  arr[1] = 2
  arr[2] = 1
  fmt.Println(validate(arr, 2, 8, 2))
}


package main

import "fmt"

func toBaseSeven(number int, size int) []int {
	result := make([]int, size)
	for i := range result {
		result[i] = number % 7
		number /= 7
	}
	return result
}

func checkDistinctOfNumbers(hour []int, minute [] int) bool {
	var numbers [7]int
	for _, v := range hour {
		numbers[v]++
	}

	for _, v := range minute {
		numbers[v]++
	}

	for _, v := range numbers {
		if v > 1 {
			return false
		}
	}

	return true
}

func sizeInBaseSeven(number int) int {
	res := 1
	for number /= 7; number != 0; number /= 7 {
		res++
	}
	return res
}

func main() {
	var n, m, res int
	fmt.Scan(&n, &m)
	n_size, m_size := sizeInBaseSeven(n-1), sizeInBaseSeven(m-1)
	if n_size + m_size > 7 {
		fmt.Println("0")
		return
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if checkDistinctOfNumbers(toBaseSeven(i, n_size), toBaseSeven(j, m_size)) {
				res++
			}
		}
	}
	fmt.Println(res)
}


package main

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

func main(){
	var n, m, k int
	var a [50]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	sum := 0
	x := 0
	i := 0
	for i=0; i<n; i++ {
		r.Scan()
		x, _ = strconv.Atoi(r.Text())
		a[x-1] += 1
	}
	for m>k {
		for i=49; i>=0; i-- {
			if a[i] > 0 {
				k += i;
				a[i] -= 1
				sum += 1
				break
			}
		}
		if i<0 {
			w.WriteString("-1\n")
			w.Flush()
			return
		}
	}
	w.WriteString(strconv.Itoa(sum)+"\n")
	w.Flush()
}


package main

import (
    "fmt"
    "sort"
)

func main() {
    var n,m,k int
    fmt.Scan(&n,&m,&k)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    for ; (k > 0) && (m > 0); k-- {
        if (m <= k) { m = 0; break; }
        if k == 1 {
            for (len(a) != 0) && (a[len(a)-1] > 1){
                m -= a[len(a)-1]
                a = a[:len(a)-1]
                if (m > 0) { m++ } else { break }
            }
        } else {
            if len(a) != 0 {
                m -= a[len(a)-1]
                a = a[:len(a)-1]
            } else {
                m--
            }
        }
    }
    if (m > 0) { fmt.Println(-1) } else { fmt.Println(n-len(a)) }
}


// 257A-mic_rizal
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, m, k, i, x, l int
    fmt.Scan(&n, &m, &k)
    var a []int
    for i = 1; i <= n; i++ {
        fmt.Scan(&x)
        a = append(a, x)
        l++
    }
    sort.Sort(sort.IntSlice(a))
    pos := n - 1
    for k < m && pos >= 0 {
        k += a[pos] - 1
        pos--
    }
    if k < m {
        fmt.Println("-1")
    } else {
        fmt.Println(n - pos - 1)
    }
}


package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

type Vertice struct {
	X int
	Y int
}

func dist(a, b Vertice) int {
	x, y := a.X-b.X, a.Y-b.Y
	return x*x + y*y
}

func isRight(a, b, c Vertice) bool {
	es := []int{dist(a, b), dist(b, c), dist(c, a)}
	sort.Ints(es)

	if es[0] == 0 || es[1] == 0 || es[2] == 0 {
		return false
	}

	return es[0]+es[1] == es[2]
}

func getAdjs(v Vertice) []Vertice {
	return []Vertice{Vertice{v.X - 1, v.Y}, Vertice{v.X + 1, v.Y}, Vertice{v.X, v.Y - 1}, Vertice{v.X, v.Y + 1}}
}

func solve(a, b, c Vertice) string {
	if isRight(a, b, c) {
		return "RIGHT"
	}

	for i := 0; i < 3; i++ {
		var v1, v2, v3 Vertice
		switch i {
		case 0:
			v1, v2, v3 = a, b, c
		case 1:
			v1, v2, v3 = b, c, a
		case 2:
			v1, v2, v3 = c, a, b
		}
		adjs := getAdjs(v1)
		for _, v := range adjs {
			if isRight(v, v2, v3) {
				return "ALMOST"
			}
		}
	}

	return "NEITHER"
}

func main() {
	defer w.Flush()

	a, b, c := Vertice{}, Vertice{}, Vertice{}
	fmt.Fscanf(r, "%d %d %d %d %d %d", &a.X, &a.Y, &b.X, &b.Y, &c.X, &c.Y)

	fmt.Fprintf(w, "%v", solve(a, b, c))
}


package main

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

func main() {

	reader := bufio.NewReader(os.Stdin)
	var n, p int64

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

	for i := int64(1); i < 40; i++ {
		tmp := n - i*p
		if bits.OnesCount64(uint64(tmp)) <= int(i) && tmp >= i {
			fmt.Println(i)
			return
		}
	}

	fmt.Println(-1)
}


package main

import (
	. "fmt"
	"math/bits"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, p int
	Scan(&n, &p)
	for i := 1; i*p < n; i++ {
		if x := n - i*p; i <= x && i >= bits.OnesCount(uint(x)) {
			Print(i)
			return
		}
	}
	Print(-1)
}


package main

import "fmt"

func main() {
	n,p:=0,0
	fmt.Scanln(&n,&p)
	for i := 1; i<=64; i++ {
		fuck:=n-p*i
			s:=fmt.Sprintf("%b",fuck)
			ans:=0
			for i := 0; i < len(s); i++ {
				if s[i]=='1'{
					ans++
			}
			}
			//fmt.Println(fuck,s,ans,i)
			if ans<=i&&i<=n-p*i{
				fmt.Println(i)
				return
			}

	}
	fmt.Println(-1)

}


package main

import (
	"fmt"
	// "os"
	)

const INF = 0x3f3f3f3f

var n, m, tot int

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

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

func main() {
	// fd, _ := os.Open("in.txt")
	// os.Stdin = fd
	var T int = 1
	// fmt.Scanf("%d", &T)
	for ci:=1; ci<=T; ci++ {
		fmt.Scanf("%d %d\n", &n, &m)
		// fmt.Printf("Case #%d: ", ci)
		var ans int = 107
		for i:=1; i<=n; i++ {
			var x int
			fmt.Scanf("%d", &x)
			if m%x==0 {
				ans = min(ans, m/x)
			}
		}
		fmt.Printf("%d\n", ans)
	}
}


package main

import "fmt"

func main() {
	var n, k, a int
	fmt.Scan(&n, &k)
	min := 100
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if k%a == 0 && min > k/a {
			min = k / a
		}
	}
	fmt.Println(min)
}


package main

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

func main() {
	var n, k, a, x int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Fscanf(stdin, "%d", &a)
		if k%a == 0 {
			x = max(x, a)
		}
	}
	fmt.Println(k / x)
}

func max(a int, b int) int {
	return int(math.Max(float64(a), float64(b)))
}


package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
		n,m := reader.NextInt64(),reader.NextInt64()
		aa:=make([]int64,101)
		for i:=int64(0);i<m;i++ {
			x:=reader.NextInt64()
			aa[x]++
		}
		for d:=int64(100);d>0;d-- {
		tmp := make([]int64, len(aa))
		copy(tmp, aa)
		max:=int64(0)
		for i:=1;i<=100;i++ {
			for tmp[i]>=d {
				max++
				tmp[i]-=d
			}
			if(max>=n){
				writer.Printf("%d\n",d)
				return
			}
		}
	}
	writer.Printf("0")
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	arr := make(map[int]int)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscan(reader, &x)
		arr[x]++
	}

	var mx int
	for i := 1; i < 101; i++ {
		var count int
		for _, vl := range arr {
			count += vl / i
		}

		if count >= n {
			mx = i
		}
	}

	fmt.Println(mx)
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	numMap := make(map[int]int)
	for i := 0; i < m; i++ {
		t := 0
		fmt.Fscanf(in, "%d", &t)
		numMap[t] = numMap[t] + 1
	}
	ans := 0
	for i := 1; i < 1000; i++ {
		people := 0
		for _, v := range numMap {
			people += v / i
		}
		if people < n {
			break
		}
		ans = i
	}

	fmt.Fprintf(out, "%d\n", ans)
	return
}


package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	type pair struct{ a0, len int }
	const mx = 1e5 + 5
	ps := [mx][]pair{}
	sgSum := [mx]int{}

	var n int
	Scan(&n)

	for len := 2; len*(len+1)/2 <= n; len++ {
		for a0 := 1; ; a0++ {
			s := (2*a0 + len - 1) * len / 2
			if s > n {
				break
			}
			ps[s] = append(ps[s], pair{a0, len})
		}
	}

	for i := 3; i <= n; i++ {
		mex := map[int]bool{}
		for _, p := range ps[i] {
			s := sgSum[p.a0] ^ sgSum[p.a0+p.len]
			if i == n && s == 0 {
				Print(p.len)
				return
			}
			mex[s] = true
		}
		sg := 0
		for ; mex[sg]; sg++ {
		}
		sgSum[i+1] = sgSum[i] ^ sg
	}
	Print(-1)
}


package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	n := 0
	Scan(&n)

	type pair struct{ a0, len int }
	const mx = 1e5
	ps := [mx + 1][]pair{}
	for l := 2; l*(l+1)/2 <= mx; l++ {
		for a0 := 1; ; a0++ {
			s := (2*a0 + l - 1) * l / 2
			if s > mx {
				break
			}
			ps[s] = append(ps[s], pair{a0, l})
		}
	}
	sg := [mx + 1]int{}
	for i := range sg {
		mex := map[int]bool{}
		for _, p := range ps[i] {
			s := 0
			for j := p.a0; j-p.a0 < p.len; j++ {
				s ^= sg[j]
			}
			if i == n && s == 0 {
				Print(p.len)
				return
			}
			mex[s] = true
		}
		for ; mex[sg[i]]; sg[i]++ {
		}
	}
	Print(-1)
}


package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	type pair struct{ a0, len int }
	const mx = 1e5 + 5
	ps := [mx][]pair{}
	for l := 2; l*(l+1)/2 < mx; l++ {
		for a0 := 1; ; a0++ {
			s := (2*a0 + l - 1) * l / 2
			if s >= mx {
				break
			}
			ps[s] = append(ps[s], pair{a0, l})
		}
	}
	sgSum := [mx]int{}

	var n int
	Scan(&n)
	for i := 3; i <= n; i++ {
		mex := map[int]bool{}
		for _, p := range ps[i] {
			s := sgSum[p.a0] ^ sgSum[p.a0+p.len]
			if i == n && s == 0 {
				Print(p.len)
				return
			}
			mex[s] = true
		}
		sg := 0
		for ; mex[sg]; sg++ {
		}
		sgSum[i+1] = sgSum[i] ^ sg
	}
	Print(-1)
}


package main

//14:17

import (
    "fmt"
    "math"
)

func main() {
    var n, m int64
    fmt.Scanf("%d %d", &n, &m)
    var a, b int64
    var sol int64
    var min int64
    min = math.MaxInt64
    for a = 0; a <= n/2; a++ {
        b = n - 2*a
        if (a+b)% m == 0 {
            sol = a + b
            if sol < min {
                min = sol
            }
        }
    }
    if min == math.MaxInt64 {
        fmt.Printf("-1")
    } else {
        fmt.Printf("%d", min)
    }
}


package main

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

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

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

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    m := nextInt()
    for i := m; i <= n; i += m {
        for j := 0; j <= i; j++ {
            if j * 2 + (i - j) == n {
                fmt.Fprintln(out, i)
                return
            }
        }
    }
    fmt.Fprintln(out, -1)
}


package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)
	if m > n {
		fmt.Println(-1)
		return
	}
	if n == m {
		fmt.Println(n)
		return
	}
	//var x = (n/2 + n%2) / m
	var y = (n/2 + n%2) % m
	var tot = n/2 + n%2
	if y > 0 {
		tot += m - y
	}
	fmt.Println(tot)
}


package main

import "fmt"

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

func main() {
	nums := make([]int64, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&nums[i])
	}

	minDiv := int64(7 * 1e8)

	divs := make([]int64, 3)
	divs[0] = nums[0] / 3
	divs[1] = nums[1] / 2
	divs[2] = nums[2] / 2

	for i := 0; i < 3; i++ {
		if divs[i] < minDiv {
			minDiv = divs[i]
		}
	}

	var result int64
	result += minDiv * 7

	nums[0] -= minDiv * 3
	nums[1] -= minDiv * 2
	nums[2] -= minDiv * 2

	var maxDays int64
	for i := 0; i < 7; i++ { // 何日目からか
		a, b, c := nums[0], nums[1], nums[2]
		var days int64
		for j := 0; j < 7; j++ { // 何日分進んだか
			k := i + j
			if k > 6 {
				k -= 7
			}
			if k == 0 || k == 3 || k == 6 {
				if a == 0 {
					break
				}
				a--
			}
			if k == 1 || k == 5 {
				if b == 0 {
					break
				}
				b--
			}
			if k == 2 || k == 4 {
				if c == 0 {
					break
				}
				c--
			}
			days++
		}
		maxDays = max(maxDays, days)
	}
	fmt.Println(maxDays + result)
}


// Author: sighduck
// URL: https://codeforces.com/contest/1154/problem/C

package main

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

func min(a []int) int {
	minElem := a[0]
	for i := 1; i < 3; i++ {
		if a[i] < minElem {
			minElem = a[i]
		}
	}
	return minElem
}

func simulate(a int, b int, c int, day int) int {
	week := []string{"f", "r", "c", "f", "c", "r", "f"}
	daysFed := 0
	for {
		currentDay := day % 7
		if week[currentDay] == "f" && a > 0 {
			a -= 1
			daysFed += 1
		} else if week[currentDay] == "r" && b > 0 {
			b -= 1
			daysFed += 1
		} else if week[currentDay] == "c" && c > 0 {
			c -= 1
			daysFed += 1
		} else {
			break
		}
		day += 1
	}
	return daysFed
}

func simulateAll(a, b, c int) int {
	maxDays := 0
	for i := 0; i < 7; i++ {
		days := simulate(a, b, c, i)
		if days > maxDays {
			maxDays = days
		}
	}
	return maxDays
}

func Solve(a, b, c int) int {
	arr := []int{a / 3, b / 2, c / 2}
	minWeeks := min(arr)
	a -= 3 * minWeeks
	b -= 2 * minWeeks
	c -= 2 * minWeeks
	return 7*minWeeks + simulateAll(a, b, c)
}

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

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

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


package main

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

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

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

func main() {
  defer writer.Flush()
  var a, b, c int
  scanf("%d %d %d\n", &a, &b, &c)
  solve(a, b, c)
}

// a b c a c b a
func solve(a, b, c int) {
  min := a / 3
  if b/2 < min {
    min = b / 2
  }
  if c/2 < min {
    min = c / 2
  }
  a -= min * 3
  b -= min * 2
  c -= min * 2
  max := 0
  food := []int{0, 1, 2, 0, 2, 1, 0}
  for start := range food {
    temp := 0
    cur := start
    store := []int{a, b, c}
    for true {
      cur %= 7
      store[food[cur]]--
      if store[food[cur]] < 0 {
        break
      } else {
        temp++
      }
      cur++
    }
    if temp > max {
      max = temp
    }
  }
  printf("%d\n", max+7*min)
}


package main

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

type vallen struct {
	len, val int
}

var orders [10]vallen = [...]vallen{
	{1000000000, 512},
	{100000000, 256},
	{10000000, 128},
	{1000000, 64},
	{100000, 32},
	{10000, 16},
	{1000, 8},
	{100, 4},
	{10, 2},
	{1, 1},
}

func solve() {
	n := readString()
	s := make([]byte, len(n))

	rest := false
	for i, c := range n {
		if rest {
			s[i] = '1'
			continue
		}
		if c >= '2' {
			rest = true
			s[i] = '1'
			continue
		}
		s[i] = n[i]
	}
	var r int
	fmt.Sscanf(string(s), "%b", &r)
	fmt.Println(r)
}

func solve2() {
	n := readInt()
	r := 0

	b := 1 << 30
	for ; b > 0; b >>= 1 {
		r |= b
		if r > n {
			r &= ^b
		}
	}
	fmt.Sscanf(fmt.Sprintf("%d", r), "%b", &r)
	fmt.Println(r)
}

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()
	//solve2()
}

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

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

	n := readNum(reader)

	fmt.Println(solve(n))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int) int {
	xs := make([]int, 0, 10)
	num := n
	var i int
	for num > 0 {
		i++
		xs = append(xs, num%10)
		num /= 10
	}

	if xs[i-1] > 1 {
		return pow(2, i) - 1
	}
	var res int
	// 112 => 100, 110, 111, 101
	// 102 => 100, 101
	for i > 0 {
		if xs[i-1] > 1 {
			res += pow(2, i) - 1
			break
		}
		if xs[i-1] == 1 {
			// put 0 at i-1
			res += pow(2, i-1)
		}
		// put 1 or 0
		i--
	}

	return res
}

func pow(a, b int) int {
	var res = 1
	for b > 0 {
		if b&1 == 1 {
			res = (res * a)
		}
		a *= a
		b >>= 1
	}

	return res
}


package main

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

var itemList map[int64]bool

func checkNumber(list []int64, value int64) {
	var result int64
	result = 0
	length := len(list)

	for i := length - 1; i >= 0; i-- {
		if list[i] == 1 {
			result += int64(math.Pow(10, float64(length - i - 1)))
		}
	}

	if result >= 1 && result <= value {
		itemList[result] = true
	}
}

func calc(list []int64, length int64, startsWith int64, value int64) {
	if startsWith < length {
		checkNumber(list, value)
		calc(append([]int64{}, list...), length, startsWith + 1, value)

		list[startsWith] = 1

		checkNumber(list, value)
		calc(append([]int64{}, list...), length, startsWith + 1, value)
	}
}

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

	input, _, _ := reader.ReadLine()
	value, _ := strconv.Atoi(string(input))

	itemList = make(map[int64]bool, 0)

	digitCount := int64(math.Log10(float64(value)))+1;

	list := make([]int64, digitCount)

	calc(list, digitCount, 0, int64(value))

	fmt.Println(len(itemList))
}

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

	input, _, _ := reader.ReadLine()
	value, _ := strconv.Atoi(string(input))

	resultNumber := 0

	for i := 1; i <= value; i++ {
		newVal := strconv.Itoa(i)

		result := true

		for j := 0; j < len(newVal); j ++ {
			if string(newVal[j]) != "1" && string(newVal[j]) != "0" {
				result = false
				break
			}
		}

		if result {
			resultNumber++
		}
	}

	fmt.Println(resultNumber)
}


package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	if N == K || K == 0 {
		fmt.Println(0, 0)
		return
	}
	fmt.Println(1, min(K*2, N-K))

}

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

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

var (
        n int
        k int
)

func main() {
        fmt.Scan(&n, &k)
        min := 1
        max := k + 1
        if k <= n/3 {
                max = k * 2
        } else {
                max = n - k
        }
        if k == n || k == 0 || n == 0 {
                min = 0
                max = 0
        }
        fmt.Println(min, max)
}