package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadBytes('\n')
	var k uint64
	readUint64(s, 0, &k)
	res := solve(int64(k))
	fmt.Println(res)
}

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') && bs[x] != '-' {
			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
}

const codeforces = "codeforces"

func solve(k int64) string {
	n := len(codeforces)

	var c int = 1
	cnt := make([]int, n)
	for {
		var prod int64 = 1
		for i := 0; i < n; i++ {
			cnt[i] = c
			prod *= int64(c)
		}
		for i := n - 1; i >= 0; i-- {
			//chang i + 1 to c + 1
			if prod >= k {
				return createCodeforces(cnt)
			}
			cnt[i]++
			prod /= int64(c)
			prod *= int64(c + 1)
		}

		c++
	}
}

func product(cnt []int) int64 {
	var res int64 = 1
	for i := 0; i < len(cnt); i++ {
		res *= int64(cnt[i])
	}
	return res
}

func createCodeforces(cnt []int) string {
	var buf bytes.Buffer

	for i := 0; i < len(codeforces); i++ {
		for x := 0; x < cnt[i]; x++ {
			buf.WriteByte(codeforces[i])
		}
	}

	return buf.String()
}

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


package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	printer := bufio.NewWriter(os.Stdout)
	defer printer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var x int
		fmt.Fscan(scanner, &x)
		x = x - 1
		var arr [3]int
		for i := 0; i < 3; i++ {
			fmt.Fscan(scanner, &arr[i])
		}
		next := arr[x]
		if next == 0 {
			fmt.Fprintln(printer, "NO")
			continue outer
		}
		next = arr[next-1]
		if next == 0 {
			fmt.Fprintln(printer, "NO")
			continue outer
		}
		fmt.Fprintln(printer, "YES")
	}
}


package main

import (
	"fmt"
	"strings"
)

func main() {
	var numbers string
	var k int
	var flag1 bool
	fmt.Scan(&k)
	fmt.Scan(&numbers)
	flag1 = checking(numbers, k)
	if flag1 == true {
		fmt.Println(strings.Count(numbers, "8"))
 	} else {
		 fmt.Println(k/11)
	 }
}

func checking(str string, n int) bool {
	var flag bool
	if n/11 >= strings.Count(str, "8") {
		flag = true
	} else{
		flag = false
	}
	return flag
}


package main

import (
	"fmt"
)

func main() {
	var tt int
	fmt.Scanln(&tt)
	for j := 0; j < tt; j++ {
		var n int
		flag := false
		fmt.Scanln(&n)
		for i := 2; i*i <= n; i++ {
			if n%i == 0 {
				fmt.Printf("%v %v\n", n/i, n-n/i)
				flag = true
				break
			}
		}

		if !flag {
			fmt.Printf("%v %v\n", 1, n-1)
		}
	}

}


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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	n -= 10
	if n <= 0 {
		fmt.Println(0)
	} else if n < 10 || n == 11 {
		fmt.Println(4)
	} else if n == 10 {
		fmt.Println(15)
	} else {
		fmt.Println(0)
	}

}


package main

import (
	"fmt"
)

func main() {
	var a int
	olChar := "abcd"
	fromStoF := 0
	fromFtoS := 0

	fmt.Scanln(&a)

	var inp string
	fmt.Scan(&inp)

	for _, char := range inp {
		charNew := string(char)
		if olChar != "abcd" {
			if charNew == "S" && charNew != olChar {
				fromFtoS++
			} else if charNew == "F" && charNew != olChar {
				fromStoF++
			}
		}
		olChar = charNew
	}

	if fromStoF > fromFtoS {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


package main

import (
	"fmt"
	"math"
	"strconv"
)

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

	for i := range coluna {
		fmt.Scan(&coluna[i])
	}

	for {
		colunasFaltando := 0

		for i := len(coluna)-1; i > -1; i-- {
			if i != 0 {
				if coluna[i] < coluna[i-1] {
					colunasFaltando += 1
					dif := math.Abs( float64(coluna[i]) - float64(coluna[i-1]) )
					coluna[i] += int(dif)
					coluna[i-1] -= int(dif)
				}
			}
		}

		if colunasFaltando == 0 {
			break
		}
	}

	var s string = strconv.Itoa(coluna[0])
	for i, e := range coluna {
		if i == 0 {
			continue
		}
		s += " " + strconv.Itoa(e)
	}
	fmt.Println(s)
}


package main

import (
	"fmt"
	"os"
)

func main() {
	var n, k, a, summ, summ2 int
	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		summ2 += a
		if summ2 <= 8 {
			summ += summ2
			summ2 = 0
		} else {
			summ += 8
			summ2 -= 8
		}
		if summ >= k {
			fmt.Println(i + 1)
			os.Exit(0)
		}
	}
	fmt.Println("-1")
}


package main
import "fmt"

var s75 = "What are you doing at the end of the world? Are you busy? Will you save us?"
var s34 = "What are you doing while sending \""
var s32 = "\"? Are you busy? Will you send \""
var s2 = "\"?"

var f = make([]uint64, 100001)

func printChar(n int, k uint64) {
	if k > f[n] {
		fmt.Print(".")
		return
	}

	if n == 0 {
		fmt.Print(string(s75[k-1]))
		return
	}

	if k <= 34 {
		fmt.Print(string(s34[k-1]))
		return
	}

	k -= 34
	if k <= f[n-1] {
		printChar(n-1, k)
		return
	}

	k -= f[n-1]
	if k <= 32 {
		fmt.Print(string(s32[k-1]))
		return
	}

	k -= 32
	if k <= f[n-1] {
		printChar(n-1, k)
		return
	}

	k -= f[n-1]
	fmt.Print(string(s2[k-1]))
}

// calc len(fi)
func main() {
	// 75
	//f0 := "What are you doing at the end of the world? Are you busy? Will you save us?"
	// 34 + 75(f0) + 32 + 75(f0) + 2 = 68
	//f1 := "What are you doing while sending \"" + f0 + "\"? Are you busy? Will you send \"" + f0 + "\"?"
	//nLen := len(f0)
	//fmt.Println(nLen)
	//fmt.Println(f1)

	f[0] = 75
	// range ptr/ref
	for i := 1; i < 100001; i++ {
		f[i] = 34 + f[i-1] + 32 + f[i-1] + 2
		//if f[i] < f[i-1]
		//	f[i]
	}
	//a := f[0:100]
	//for k,v := range a {
	//	fmt.Println(k, v)
	//}
	//fmt.Println(a)

	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var n int
		var k uint64
		fmt.Scan(&n, &k)
		printChar(n, k)
	}
	fmt.Println()
}


package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

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

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

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func main() {
  x, y := make([]int, 8), make([]int, 8)
  for i := 0; i < 8; i++ {
    x[i], y[i] = ni32(), ni32()
  }
  // for i := 0; i < 8; i++ {
  //   for j := i + 1; j < 8; j++ {
  //     if x[j] < x[i] || (x[j] == x[i] && y[j] < y[i]) {
  //       x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]
  //     }
  //   }
  // }
  xx, yy := make([]int, 8), make([]int, 8)
  copy(xx, x)
  copy(yy, y)
  sort.Ints(xx)
  sort.Ints(yy)
  xs, ys := []int{xx[0]}, []int{yy[0]}
  for i := 1; i < 8; i++ {
    if xx[i] != xx[i-1] {
      xs = append(xs, xx[i])
    }
    if yy[i] != yy[i-1] {
      ys = append(ys, yy[i])
    }
  }
  sort.Ints(xs)
  sort.Ints(ys)
  // fmt.Println(xs, ys)
  if len(xs) != 3 || len(ys) != 3 || xs[1] <= xs[0] || xs[2] <= xs[1] || ys[1] <= ys[0] || ys[2] <= ys[1] {
    w.WriteString("ugly\n")
    w.Flush()
    return
  }
  for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
      ug := true
      for k := 0; k < 8; k++ {
        if x[k] == xs[i] && y[k] == ys[j] {
          ug = false
        }
      }
      if ((i != 1 || j != 1) && ug) || (i == 1 && j == 1 && !ug) {
        w.WriteString("ugly\n")
        w.Flush()
        return
      }
    }
  }
  w.WriteString("respectable\n")
  w.Flush()
}


package main

import (
  "fmt"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
    if n<2 || n%2==1 {
        fmt.Println(0)
        return
    }
    k := 1;
    for i:=0;i<n/2;i++{
        k*=2
    }
    if n%2==1 {
        k*= n/2+1
    }
    fmt.Printf("%d", k)
}


package main

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

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

	var x int
	fmt.Fscanf(reader, "%d", &x);
	if x < 0 {
		x = -x
	}
	sum := 0
	for i := 0;;i ++ {
		sum += i
		if sum >= x && sum % 2 == x % 2 {
			fmt.Printf("%d", i)
			return
		}
	}
}


package main

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

func main(){
	var n, m, t 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()
	t, _ = strconv.Atoi(r.Text())
	var pa1, pa2, num int64 = 0, 0, 0
	for i:=4; i<t; i++ {
		pa1 = 1
		pa2 = 1
		for j:=1; j<=i; j++ {
			pa1 *= int64(n - i + j)
			pa1 /= int64(j)
		}
		for j:=1; j<=t-i; j++ {
			pa2 *= int64(m - (t-i)+j)
			pa2 /= int64(j)
		}
		num += pa1 * pa2
	}
	w.WriteString(strconv.FormatInt(num, 10)+"\n")
	w.Flush()
}


package main

import (
	"fmt"
	"math"
)

func min(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	var n, k int64
	fmt.Scan(&n, &k)
	var c = make([]int64, n)
	for i := range c {
		fmt.Scan(&c[i])
	}

	for i := 1; int64(i) < n; i++ {
		if c[i] > c[i-1]*2 {
			c[i] = 2 * c[i-1]
		}
	}

	var ans int64
	ans = math.MaxInt64
	var sum int64
	for i := n - 1; i >= 0; i-- {
		var need = k / (1 << uint(i))
		sum += need * c[i]
		k -= (need << uint(i))
		if k > 0 {
			ans = min(ans, sum+c[i])
		} else {
			ans = min(ans, sum)
		}
	}
	fmt.Println(ans)
}


package main

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

func solve() {
	a := []byte(strconv.FormatInt(readInt64(), 10))
	b := []byte(strconv.FormatInt(readInt64(), 10))
	anum := make([]int, len(a))
	for i := 0; i < len(a); i++ {
		anum[i] = int(a[i] - '0')
	}
	bnum := make([]int, len(b))
	for i := 0; i < len(b); i++ {
		bnum[i] = int(b[i] - '0')
	}
	sort.Sort(sort.Reverse(sort.IntSlice(anum)))
	if len(a) == len(b) {
		dfs(anum, bnum, 0)
	}
	for _, v := range anum {
		fmt.Print(v)
	}
	fmt.Println()
}

func dfs(anum []int, bnum []int, pos int) bool {
	if pos == len(anum) {
		return true
	}
	prev := -1
	for i := pos; i < len(anum); i++ {
		if anum[i] < bnum[pos] {
			anum[pos], anum[i] = anum[i], anum[pos]
			resort(anum, pos+1)
			return true
		}
		if anum[i] <= bnum[pos] && prev != anum[i] {
			anum[pos], anum[i] = anum[i], anum[pos]
			resort(anum, pos+1)
			if dfs(anum, bnum, pos+1) {
				return true
			}
			resort(anum, pos)
			prev = anum[i]
		}
	}
	return false
}

func resort(nums []int, pos int) {
	for i := pos; i < len(nums)-1; i++ {
		for j := i + 1; j < len(nums); j++ {
			if nums[i] < nums[j] {
				nums[i], nums[j] = nums[j], nums[i]
			}
		}
	}
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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


package main

import "fmt"

func gcd(a, b int) int {
	for {
		v := a % b
		a, b = b, v
		if b == 0 {
			break
		}
	}

	return a
}

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

	for {
		gone := gcd(a, n)
		n -= gone
		if n == 0 {
			fmt.Print(0)
			break
		}

		gone = gcd(b, n)
		n -= gone
		if n == 0 {
			fmt.Print(1)
			break
		}
	}
}


package main

import (
	"fmt"
)

func main() {
	var p,x,y int
	fmt.Scan(&p,&x,&y)
	ans:=(p*y-1)/100-x+1
	if ans<0 {
		ans=0
	}
	fmt.Println(ans)
}


package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)
	ma := 0
	for i := 0; i < k; i++ {
		var r int
		fmt.Scan(&r)
		if ma < r {
			ma = r
		}
	}
	ans := ma - 25
	if ans < 0 {
		ans = 0
	}
	fmt.Println(ans)
}


package main

import ("fmt"
	"sync"

	"math"
)

type changer func(int64) (int64, int)

var min struct {
  	mt sync.RWMutex
	data int
}

func decision(p int64, x int64, y int64,  f changer, wg* sync.WaitGroup )  {
	defer wg.Done()
	s := x
	randomizer := func() bool{
		i := (s / 50) % 475
		for j:=0 ; j< 25; j++ {
			i = (i * 96 + 42) % 475
			if 26+i == p {
				return true
			}
		}
		return false
	}
	cur := 0
	flag := true
	for;flag;{
		if randomizer() {
			min.mt.Lock()
			if min.data > cur {
				min.data = cur
			}
			min.mt.Unlock()
			return
		}
		min.mt.RLock()
		if min.data < cur {
			flag = false
		} else {
			var dt int
			s, dt  = f(s)
			cur += dt
		}
		min.mt.RUnlock()
		if y>s{
			flag = false
		}
	}
}

func decision_starter(p int64, x int64, y int64,  f changer, wg* sync.WaitGroup) {
	wg.Add(1)
	decision(p,x,y,f,wg)
}

func main()  {
	strat1 := func(num int64)(int64,int) {
		num+=100
		return num,1
	}
	strat2 := func(num int64)(int64,int) {
		num-=50
		return num,0
	}
	flag := true
	strat3 := func(num int64)(int64,int) {
		if flag {
			num+=50
			flag = false
			return num,1
		}

		num+=100
		return num,1
	}
	var p,x,y int64
	wg := sync.WaitGroup{}
	fmt.Scanf("%d %d %d",&p,&x,&y)
	//26 7258 6123
	//p = 26
	//x = 7258
	//y = 6123
	min.data = math.MaxInt32
	decision_starter(p,x,y,strat1,&wg)
	decision_starter(p,x,y,strat2,&wg)
	decision_starter(p,x,y,strat3,&wg)
	wg.Wait()
	min.mt.RLock()
	fmt.Printf("%d ",min.data)
	min.mt.RUnlock()
}


package main

import (
	"fmt"
)

func div8(s string) (bool, int) {
	seenDigits := make(map[int]bool)
	seenTwoDigits := make(map[int]bool)
	for i := len(s) - 1; i >= 0; i-- {
		digit := int(s[i] - '0')

		if digit == 8 || digit == 0 {
			return true, digit
		}

		// fmt.Println("Digit", digit)

		for seenTwoDigit := range seenTwoDigits {
			threeDigit := digit*100 + seenTwoDigit
			// fmt.Println("Checked three", threeDigit)
			if (threeDigit)%8 == 0 {
				return true, threeDigit
			}
		}

		for seenDigit := range seenDigits {
			twoDigit := digit*10 + seenDigit
			// fmt.Println("Checked two", twoDigit)
			if twoDigit != 0 && (twoDigit)%8 == 0 {
				return true, twoDigit
			}
			seenTwoDigits[twoDigit] = true
		}

		seenDigits[digit] = true
	}

	return false, 0
}

func main() {
	var s string
	fmt.Scanf("%s\n", &s)

	if valid, i := div8(s); valid {
		fmt.Println("YES")
		fmt.Println(i)
	} else {
		fmt.Println("NO")
	}
}


package main

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

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

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

func main() {
	defer writer.Flush()
	var n, tot int
	scanf("%d\n", &n)
	arr := []int{}
	ans := []int{}
	ans = append(ans, 1)
	for i := 0; i < n; i++ {
		var t int
		scanf("%d", &t)
		tot += t
		arr = append(arr, t)
	}
	cur := arr[0]
	for i := 1; i < n; i++ {
		if arr[i]*2 <= arr[0] {
			cur += arr[i]
			ans = append(ans, i+1)
		}
	}
	if cur > tot-cur {

		printf("%d\n", len(ans))
		for i := 0; i < len(ans); i++ {
			printf("%d ", ans[i])
		}
	} else {
		printf("0")
	}
}


package main

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

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

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

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

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

func main() {
	var r, g, b int64
	for I(&r, &g, &b) == nil {
		solve(r, g, b)
	}
	w.Flush()
}

func solve(r, g, b int64) {
	ans := (r + g + b) / 3
	min(&ans, r+g)
	min(&ans, r+b)
	min(&ans, b+g)
	O(ans, "\n")
}

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


// cf483a project main.go
package main

import (
	"fmt"
)

func main() {
	var l, r int64
	var a, b, c int64
	fmt.Scan(&l, &r)
	if r-l < 2 {
		fmt.Println(-1)
	} else {
		a = l
		b = l + 1
		for a < r-1 && b < r {
			for c = b + 1; c <= r; c++ {
				f := true
				for j := 2; j < 50; j++ {
					if b%int64(j) == 0 && c%int64(j) == 0 {
						f = false
						break
					}
				}
				if f {
					flag := false
					for i := 2; i < 50; i++ {
						if a%int64(i) == 0 && c%int64(i) == 0 {
							flag = true
							break
						}
					}
					if flag {
						break
					}
				}
			}
			if c <= r {
				break
			} else {
				a++
				b++
			}
		}
		if c > r {
			fmt.Println(-1)
		} else {
			fmt.Println(a, b, c)
		}

	}

}


package main

import "fmt"

func check(s1,s2 string, f *[105]bool) bool {
    for _, v1 := range s1 {
        found := false
        for i, v2 := range s2 {
            if (v1 == v2) && !f[i] {
                f[i] = true
                found = true
                break
            }
        }
        if !found { return false }
    }
    return true
}

func main() {
    var guest,host,pile string
    var f [105]bool
    fmt.Scan(&guest,&host,&pile)
    ans := true
    if (len(pile) != (len(guest)+len(host))) {
        ans = false
    } else {
        ans = ans && check(guest,pile,&f)
        ans = ans && check(host,pile,&f)
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}


package main

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

func main() {
	buf := &bytes.Buffer{}
	for i := 0; i < 400; i++ {
		fmt.Fprintf(buf, "%d", i)
	}
	fmt.Println(buf.Bytes()[getInt()] - '0')
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

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


// 62A-mic
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, x, y, res int
	fmt.Scan(&a, &b, &c, &d, &x, &y)
	for i := x; i <= y; i++ {
		if ((((i % a) % b) % c) % d) == i {
			res++
		}
	}
	fmt.Println(res)
}


package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextLong()
	K := io.NextLong()

	if K >= 1024 {
	  io.Println("No")
	  return
	}

	for i := int64(1); i <= K; i++ {
	  if (N + 1) % i != 0 {
	    io.Println("No")
	    return
	  }
	}
	io.Println("Yes")
}

func smallestDivisor(n int64) int64 {
  if n % 2 == 0 {
    return 2
  }
  for d := int64(3); d * d <= n; d += 2 {
    if n % d == 0 {
      return d
    }
  }
  return n
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

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

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

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

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


package main

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

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

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

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

func nextInt() int {
	v, _ := strconv.Atoi(nextToken())
	return v
}

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

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

func printInt(x int) {
	writer.WriteString(strconv.Itoa(x))
}

var n int
var s string
var a [500][500]int

func main() {
	n = nextInt()
	s = nextToken()
	x, y := 250, 250
	a[x][y] = 1
	ans := 0
	for _, c := range s {
		switch c {
		case 'U':
			y++
		case 'D':
			y--
		case 'L':
			x--
		case 'R':
			x++
		}
		ans += a[x][y]
		a[x][y]++
	}
	printInt(ans)
	writer.Flush()
}


package main

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

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

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

func innout(a, t [5]int) (int, int) {
	var in, out int
	for i := range a {
		d := t[i]/2 - a[i]
		if d > 0 {
			in += d
		} else {
			out += -d
		}
	}
	return in, out
}

func main() {
	n := readInt()
	var a, b, t [5]int
	for i := 0; i < n; i++ {
		a[readInt()-1]++
	}
	for i := 0; i < n; i++ {
		b[readInt()-1]++
	}
	for i := range t {
		t[i] = a[i] + b[i]
		if t[i]%2 != 0 {
			fmt.Println("-1")
			return
		}
	}
	ina, outa := innout(a, t)
	inb, outb := innout(b, t)
	if ina != outb || outa != inb {
		fmt.Println("-1")
		return
	}
	fmt.Println((ina + outa) / 2)
}


package main
import "fmt"

func mask(a int) int{
	b := 0
	bas := 1
	for a>0{
		if (a%10 == 7 || a%10 == 4){
			b+=bas*(a%10)
			bas*=10
		}
		a/=10
	}
	return b
}

func main (){
	var a, b int
	fmt.Scan(&a, &b)
	for c:= a+1;;c++{
		if(mask(c)==b){
			fmt.Print(c)
			break
		}
	}
}


package main

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

const N = 11

type Deck struct {
	cards []int
}

func (d *Deck) addCard(c int) {
	d.cards = append(d.cards, c)
}

func (d *Deck) isLosing() bool {
	return len(d.cards) == 0
}

func (d *Deck) hash() int64 {
	var h int64
	for _, c := range d.cards {
		h = N*h + int64(c+1)
	}
	return h
}

func oneRound(d1, d2 *Deck) {
	var c1, c2 int
	c1, d1.cards = d1.cards[0], d1.cards[1:]
	c2, d2.cards = d2.cards[0], d2.cards[1:]
	d := d1
	if c1 < c2 {
		c1, c2 = c2, c1
		d = d2
	}
	d.addCard(c2)
	d.addCard(c1)
}

func makeKey(d1, d2 Deck) string {
	return strconv.FormatInt(d1.hash(), N) + "#" + strconv.FormatInt(d2.hash(), N)
}

func main() {
	nextInt()
	var d1, d2 Deck
	k1 := nextInt()
	for i := 0; i < k1; i++ {
		d1.addCard(nextInt() - 1)
	}
	k2 := nextInt()
	for i := 0; i < k2; i++ {
		d2.addCard(nextInt() - 1)
	}
	was := make(map[string]struct{})
	for rounds := 0; ; rounds++ {
		if d1.isLosing() {
			fmt.Println(rounds, 2)
			return
		}
		if d2.isLosing() {
			fmt.Println(rounds, 1)
			return
		}
		key := makeKey(d1, d2)
		if _, ok := was[key]; ok {
			break
		}
		was[key] = struct{}{}
		oneRound(&d1, &d2)
	}
	fmt.Println(-1)
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}


package main
import "fmt"

func main() {
	sdeck := make([]string, 8)
	for i := 0; i < 8; i++{
		fmt.Scan(&sdeck[i])
	}
	var deck [8][8]int
	count := 0
	for i, s := range sdeck{
		for j, c := range s{
			if c == 'B'{
				deck[i][j] = 1
			}else{
				deck[i][j] = 0
			}
		}
	}
	for i := 0; i < 8; i++{
		sum := 0
		for j := 0; j < 8; j++ {
			if deck[i][j] == 1{
				sum++
			}
		}
		if sum == 8 {
			count++
		}
	}
	if count < 8{
		for i := 0; i < 8; i++{
			sum := 0
			for j := 0; j < 8; j++ {
				if deck[j][i] == 1{
					sum++
				}
			}
			if sum == 8 {
				count++
			}
		}
	}
	fmt.Print(count)
}


package main

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

var (
	mod int64 = 1000000007
)

func range3(l int64) []int64 {
	ans := make([]int64, 3)
	ans[0] = l / 3
	ans[1] = (l + 2) / 3
	ans[2] = (l + 1) / 3
	return ans
}
func solve(l, r int64) []int64 {
	ans := range3(r)
	lans := range3(l - 1)
	for i := 0; i < 3; i++ {
		ans[i] -= lans[i]
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	var l, r int64
	fmt.Fscanf(buf, "%d %d %d\n", &n, &l, &r)

	cnt := solve(l, r)
//	fmt.Printf("cnt=%v\n",cnt)
	dp := make([][]int64, 2)
	dp[0] = make([]int64, 3)
	dp[1] = make([]int64, 3)
	f := 1
	dp[0][0] = cnt[0]
	dp[0][1] = cnt[1]
	dp[0][2] = cnt[2]
//	fmt.Printf("ans=%v\n",dp[0])
	for i := 0; i < n-1; i++ {
		pre := f^1
		for j:=0;j < 3;j++{
			dp[f][j] = 0
			for k:=0;k < 3;k++{
				to := (3+j-k)%3
				dp[f][j] += (dp[pre][k]*cnt[to])%mod
				dp[f][j] = dp[f][j]%mod
			}
		}
	//	fmt.Printf("ans=%v\n",dp[f])
		f = pre

	}
	fmt.Printf("%d\n", dp[f^1][0])

}


package main

import (
	"fmt"
	"strconv"
)

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

	for ; l <= r; l++ {
		var m = make(map[int32]struct{})
		lStr := strconv.Itoa(l)

		for _, c := range lStr {
			m[c] = struct{}{}
		}

		if len(m) == len(lStr) {
			fmt.Println(lStr)
			return
		}
	}

	fmt.Println(-1)
}


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

  weights := map[rune]int{
    'Q': 9, 'R': 5, 'B': 3, 'N': 3, 'P': 1,
    'q': -9, 'r': -5, 'b': -3, 'n': -3, 'p': -1 }
  total := 0
  for r := 0; r < 8; r++ {
    s := getS()
    for _, char := range s {
      total += weights[char]
    }
  }
  result := "Draw"
  if total > 0 {
    result = "White"
  } else if total < 0 {
    result = "Black"
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}


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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanInt := func() int {
		scanner.Scan()
		num, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		return num
	}

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

	solutionCount := uint(math.Pow(2.0, float64(n)))
	for i := uint(0); i < solutionCount; i++ {
		sum := 0
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 == 1 {
				sum += a[j]
			} else {
				sum -= a[j]
			}
		}
		if sum%360 == 0 {
			fmt.Println("YES")
			os.Exit(0)
		}
	}

	fmt.Println("NO")
}


package main

import "fmt"

func main() {
	var n, t int
	var line string
	fmt.Scan(&n, &t, &line)

	queue := []byte(line)
	for i := 0; i < t; i++ {
		for j := 0; j < len(queue)-1; j++ {
			if queue[j] == 'B' && queue[j+1] == 'G' {
				queue[j], queue[j+1] = queue[j+1], queue[j]
				j++
			}
		}
	}

	fmt.Print(string(queue))

}


package main
import "fmt"

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


package main

import "fmt"

func main() {
	var t int64
	var n int64
	var m int64
	var k int64
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}
	for i := int64(0); i < t; i++ {
		var h int64
		_, err = fmt.Scan(&n)
		if err != nil {
			return
		}
		_, err = fmt.Scan(&m)
		if err != nil {
			return
		}
		_, err = fmt.Scan(&k)
		if err != nil {
			return
		}

		if n%2 == 1 {
			h = m / 2
		}

		if k < h {
			fmt.Println("NO")
			continue
		}

		if (k-h)%2 == 1 {
			fmt.Println("NO")
			continue
		}

		if m%2 == 1 {
			if n*(m-1)<k*2 {
				fmt.Println("NO")
				continue
			}
		}
		fmt.Println("YES")
	}
}


package main

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

func main() {
	var n, t, k, d int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &t)
	fmt.Fscan(reader, &k)
	fmt.Fscan(reader, &d)
	before := n / k * t
	if n%k != 0 {
		before += t
	}
	if n < k {
		fmt.Println("NO")
	} else if before <= t+d {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}


package main
import (
	"fmt"
)

func cmp_slice_int(a, b []int) bool {
	la, lb := len(a), len(b)
	if la != lb {
		return false
	}
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

func main() {
	var n, l int
	fmt.Scanln(&n, &l)

	a := make([]int, n, n)
	b := make([]int, n, n)

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

	for i := 0; i < l; i++ {
		if cmp_slice_int(a, b) {
			fmt.Println("YES")
			return
		}
		for j := 0; j < n; j++ {
			a[j]++
		}
		if a[n-1] >= l {
			a = append(a[n-1:], a[:n-1]...)
			a[0] = a[0] % l
		}
	}

	fmt.Println("NO")
}


package main
import (
	"fmt"
)
func main() {
	var n,k,l,c,d,p,nl,np,a int
	fmt.Scan(&n,&k,&l,&c,&d,&p,&nl,&np)
	k*=l
	c*=d
	k/=nl
	p/=np
	if k>p {
		a=p
	} else {a=k}
	if a>c {
		a=c
	}
	fmt.Println(a/n)
}


package main

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

var scanner *bufio.Scanner
var t [1e6 + 1]bool

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

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

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

func main() {
	init_scanner()
	size, ans := readInt(), 0
	m := make(map[int]bool)
	for i := 0; i < size; i++ {
		x := readInt()
		if x > 0 && !m[x] {
			ans += 1
			m[x] = true
		}
	}
	fmt.Println(ans)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF16C(in io.Reader, out io.Writer) {
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	var a, b, x, y int
	Fscan(in, &a, &b, &x, &y)
	g := gcd(x, y)
	x /= g
	y /= g
	k := a / x
	if b/y < k {
		k = b / y
	}
	if k > 0 {
		Fprint(out, x*k, y*k)
	} else {
		Fprint(out, 0, 0)
	}
}

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


package main

import (
	"fmt"
)

func main() {
	var friendsCount, pagesCount, answer int
	fmt.Scan(&friendsCount, &pagesCount)

	answer =
		(friendsCount*8)/pagesCount +
			(friendsCount*5)/pagesCount +
			(friendsCount*2)/pagesCount

	if friendsCount*8%pagesCount != 0 {
		answer++
	}

	if friendsCount*5%pagesCount != 0 {
		answer++
	}

	if friendsCount*2%pagesCount != 0 {
		answer++
	}

	fmt.Println(answer)
}


package main

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

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

	i, j := 0, 0

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

	return j == len(t)
}

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

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

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

	// reader := bufio.NewReader(file)

	reader := bufio.NewReader(os.Stdin)

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

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

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

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

	fmt.Println(maxLen)

}


package main

import "fmt"

func main() {
	var totalNum, currentNum, showSize int
	fmt.Scanf("%d", &totalNum)
	fmt.Scanf("%d", &currentNum)
	fmt.Scanf("%d", &showSize)

	if currentNum - showSize > 1 {
		fmt.Print("<< ")
	}
	for i := showSize; i >0; i-- {

		showNum := currentNum - i
		if showNum >= 1 {
			fmt.Printf("%d ", currentNum - i)
		} else {
			continue
		}
	}
	fmt.Printf("(%d)", currentNum)
	for i := 1; i <= showSize; i++ {
		showNum := currentNum + i
		if showNum > totalNum {
			break
		} else {
			fmt.Printf(" %d", showNum)
		}
	}
	if(currentNum + showSize < totalNum) {
		fmt.Print(" >>")
	}
}


package main
import "fmt"

func main(){
	var n int64
	fmt.Scan(&n)
	if n%2 == 0{
		fmt.Println(2)
	}else{
		fmt.Println(1)
	}
}


package main

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

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

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

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

    scanner.Scan()
	str := scanner.Text()
	k := ReadInt()

	ast := 0
	inter := 0

	for i := 0; i < len(str); i++ {
		if string(str[i]) == "?" {
			inter++
		} else if string(str[i]) == "*" {
			ast++
		}
	}

	menor := len(str) - (2*ast) - (2*inter)
	if k < menor {
   		writer.WriteString("Impossible")
   		return
	}

	resp := ""

	if ast > 0 {
		achei := false

		rep := k - menor

		for i := 0; i < len(str)-1; i++ {
			if string(str[i+1]) == "*" && achei == false {
				achei = true
				for rep > 0 {
					resp += string(str[i])
					rep--
				}
				i++
			} else if string(str[i+1]) == "?" || string(str[i+1]) == "*" {
				i++
			} else {
				resp += string(str[i])
			}
		}

		if string(str[len(str)-1]) != "?" && string(str[len(str)-1]) != "*" {
			resp += string(str[len(str)-1])
		}

   		writer.WriteString(resp)
   		return
	}

	dif := len(str) - inter - k

	if dif < 0 {
		writer.WriteString("Impossible")
   		return
	}

	resp = ""

	for i := 0; i < len(str)-1; i++ {
		if string(str[i+1]) == "?" && dif > 0 {
			dif--
			i++
		} else if string(str[i+1]) == "?" && dif == 0 {
			resp += string(str[i])
			i++
		} else {
			resp += string(str[i])
		}
	}

	if string(str[len(str)-1]) != "?" {
		resp += string(str[len(str)-1])
	}

	writer.WriteString(resp)
}


package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	for i := 0; i < N; i++ {
		A := sc.NextInt()
		flag := false
		for k := 0; 7*k <= A; k++ {
			if (A-7*k)%3 == 0 {
				fmt.Println("YES")
				flag = true
				break
			}
		}
		if !flag {
			fmt.Println("NO")
		}
	}

}

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


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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	yes := false
	if strings.Contains(text, "0") {
		if strings.ContainsAny(text, "123") {
			yes = true
		}
	} else {
		if strings.ContainsAny(text, "123") && strings.ContainsAny(text, "79") {
			if strings.ContainsAny(text, "147") && strings.ContainsAny(text, "369") {
				yes = true
			}
		}
	}
	if yes {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n,&s)
	g :="aeoyiu"
	var t []rune
	prev := 'n'
	for _,r := range(s) {
		if (!strings.ContainsRune(g,r) || !strings.ContainsRune(g,prev)) {
			prev = r
			t = append(t,r)
		}
	}
	fmt.Println(string(t))
}


package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	for i := 0; i <= 10000; i++ {
		if (c-i*b)%a == 0 && (c-i*b)/a >= 0 {
			fmt.Printf("Yes\n")
			return
		}
	}

	fmt.Printf("No\n")
}


package main

import (
	"fmt"
)

func main() {
	var moveNum, candyNum int

	_, err := fmt.Scanln(&moveNum, &candyNum)
	if err != nil {
	}

	for j := 0; j <= moveNum; j++ {
		i := moveNum - j
		a := 0
		if i%2 == 0 {
			a = (i + 1) * (i / 2)
		} else {
			a = ((i + 1) / 2) * i
		}
		if a < j {
			continue
		}
		candy := a - j
		if (candy - candyNum) == 0 {
			fmt.Println(j)
		}
	}
}


package main

import "fmt"

func main() {
	var n, m, a, b int
	fmt.Scanf("%d %d %d %d", &n, &m, &a, &b)
	sum := n / m * b
	if (n % m) * a > b {
		sum += b
	}else {
		sum += (n % m) * a
	}
	if n * a < sum {
		sum = n * a
	}
	fmt.Printf("%d", sum)

}


package main
import (
	"fmt"
)
func main() {
	var n uint64
	fmt.Scan(&n)
	n = n*(n*n+5)/6
	fmt.Println(n)
}


package main

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

type Bytes []byte

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

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

	sc.Scan()
	sc.Scan()

	m := map[byte]string{
		'2': "2",
		'3': "3",
		'4': "322",
		'5': "5",
		'6': "53",
		'7': "7",
		'8': "7222",
		'9': "7332",
	}

	ans := ""
	for _, x := range sc.Bytes() {
		ans += m[x]
	}

	b := Bytes(ans)
	sort.Sort(sort.Reverse(b))

	fmt.Println(string(b))
}


package main

import "fmt"

func main() {
    var n,a,ans int
    var cnt [3]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        cnt[i%3] += a
        if cnt[ans] < cnt[i%3] { ans = i%3 }
    }
    if ans == 0 {
        fmt.Println("chest")
    } else if ans == 1 {
        fmt.Println("biceps")
    } else {
        fmt.Println("back")
    }
}


package main

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

func main() {
	var n, m, k int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m, &k)
	if n <= m && n <= k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


package main

import (
	"bytes"
	"fmt"
	"strings"
	"unicode"
)

func main() {
	var s string
	fmt.Scan(&s)
	var ok = true
	for i := 1; i < len(s); i++ {
		if 'a' <= s[i] && s[i] <= 'z' {
			ok = false
			break
		}
	}
	if ok {
		var buffer bytes.Buffer
		if 'a' <= s[0] && s[0] <= 'z' {
			buffer.WriteRune(unicode.ToUpper(rune(s[0])))
		} else {
			buffer.WriteRune(unicode.ToLower(rune(s[0])))
		}

		buffer.WriteString(strings.ToLower(s[1:]))
		fmt.Print(buffer.String())
		return
	}
	fmt.Print(s)
}


package main

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

func solve(k, a, b int64) int64 {
	a0 := a / k
	b0 := b / k
	if a - a0 * k > b0 * (k - 1) {
		return -1
	}
	if b - b0 * k > a0 * (k - 1) {
		return -1
	}
	return a0 + b0
}

func main() {
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	k := cin.nextInt64()
	a := cin.nextInt64()
	b := cin.nextInt64()
	fmt.Printf("%d\n", solve(k, a, b))
}

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

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

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

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

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

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

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

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


package main

import "fmt"

const mod = 1000000007
const maxn = 1000000 + 10

var rank [maxn]int64

func myinit() {
	rank[0] = 1
	var i int64
	for i = 1; i < maxn; i++ {
		rank[i] = rank[i-1] * i % mod
	}
}
func powmod(a, n int64) int64 {
	var ans int64
	ans = 1
	var i int64
	for i = 1; i <= n; i++ {
		ans = ans * a % mod
	}
	return ans
}
func main() {
	myinit()
	var n int64
	fmt.Scan(&n)
	var ans = (rank[n] - powmod(2, n-1) + mod) % mod
	fmt.Println(ans)
}


// Author: sighduck
// URL: https://codeforces.com/contest/1150/problem/A

package main

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

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

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

func Solve(n int, m int, r int, s []int, b[]int) int {
	minBuyPrice := min(s)
	maxSellPrice := max(b)
	if maxSellPrice > minBuyPrice {
		shares := r / minBuyPrice
		remainder := r % minBuyPrice
		return shares * maxSellPrice + remainder
	}
	return r
}

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

	var n, m, r int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &r)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &s[i])
	}
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &b[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, m, r, s, b))
}


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

func main() {
	var s, t string
	fmt.Scanf("%s %s", &s, &t)

	var cnt [26]int
	for _, val := range s {
		cnt[val - 'a']++
	}
	for _, val := range t {
		cnt[val - 'a']--
		if cnt[val - 'a'] < 0 {
			fmt.Println("need tree")
			return
		}
	}
	if len(s) == len(t) {
		fmt.Println("array")
		return
	}

	var p int = 0
	for i := 0; i < len(t); i++ {
		for p < len(s) && s[p] != t[i] {
			p++
		}
		if p == len(s) {
			fmt.Println("both")
			return
		}
		p++
	}
	fmt.Println("automaton")
}


package main

import "fmt"

func main() {
	var s, x1, x2, t1, t2, p, d int
	fmt.Scan(&s, &x1, &x2, &t1, &t2, &p, &d)
	byFoot := abs(x1-x2) * t2
	wT := abs(p-x1) * t1
	if x1 < p {
		if d == 1 {
			wT += 2 * (s - p) * t1
			d = -1
		}
	} else if x1 > p {
		if d == -1 {
			wT += 2 * p * t1
			d = 1
		}
	}
	tT := abs(x1-x2) * t1
	if x1 < x2 {
		if d == -1 {
			tT += 2 * x1 * t1
		}
	} else {
		if d == 1 {
			tT += 2 * (s - x1) * t1
		}
	}

	byTrain := tT + wT
	fmt.Println(min(byFoot, byTrain))
}

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

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


package main

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

func solve() {
    n, k, s := readInt(), readInt(), readString()
    g, t := strings.Index(s, "G"), strings.Index(s, "T")
    if g > t {
        g = t
    }
    for i := g+k; i < n; i += k {
        cur := s[i]
        if cur == 'T' || cur == 'G' {
            fmt.Println("YES")
            return
        } else if cur == '#' {
            break
        }
    }
    fmt.Println("NO")
}

// Helpers

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

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

// Math

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

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

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

// IO

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

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

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

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

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

// Sort

type Ints64 []int64

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

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


package main

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

func main() {
	data := ""
	input := bufio.NewScanner(os.Stdin)
	for input.Scan() {
		data = input.Text()
		break
	}

	var (
		left  int
		right int
	)
	left = -1
	for _, el := range data {
		if string(el) != "=" {
			left++
			continue
		}
		if string(el) == "=" {
			right = len(data) - left - 2
			break
		}
	}

	if left == right {
		fmt.Println(data)
		return
	}

	if math.Abs(float64(right-left)) != 2 {
		fmt.Println("Impossible")
		return
	}

	if left < right {
		fmt.Println("|" + data[:len(data)-1])
		return
	}

	if string(data[1]) == "+" {
		fmt.Println(data[:left] + data[left+1:] + "|")
		return
	}

	fmt.Println(data[1:] + "|")
}


package main

import (
	"fmt"
)

var mod uint64 = 1000000007

func main() {
	var a, b uint64
	fmt.Scanf("%d %d", &a, &b)
	sum1 := (b - 1) * b / 2
	sum1 = sum1 % mod
	sum2 := a * (a + 1) / 2
	sum2 = sum2 % mod
	sum2 = sum2 * b
	sum2 = sum2 % mod
	sum := sum1 * (a + sum2)
	sum = sum % mod
	fmt.Println(sum)
}


package main

import (
	"fmt"
)

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

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


package main

import (
	"fmt"
	"log"
)

func main() {
	var n, k int64
	readCount, _ := fmt.Scan(&n, &k)

	if readCount != 2 {
		log.Fatal("Input is not valid! Provide 2 numbers.")
	}

	var modulo int64
	for k > 0 {
		modulo = n % 10
		if modulo == 0 {
			k--
			n = n / 10
		} else {
			if k < modulo {
				n -= k
				k = 0
			} else {
				k -= modulo
				n -= modulo
			}
		}
	}
	fmt.Print(n)
}


package main

import "fmt"
import "bufio"
import "os"

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

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

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

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

	if a[n-1] == 0 {
		fmt.Fprintf(bufout, "UP\n")
	} else if a[n-1] == 15 {
		fmt.Fprintf(bufout, "DOWN\n")
	} else if n == 1 {
		fmt.Fprintf(bufout, "-1\n")
	} else if a[n-2] < a[n-1] {
		fmt.Fprintf(bufout, "UP\n")
	} else {
		fmt.Fprintf(bufout, "DOWN\n")
	}
}


package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ex := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ex[i])
	}
	ans := 0
	for i, j := 0, n-1; i <= j && (ex[i] <= k || ex[j] <= k) ; {
		if ex[i] <= k {
			i++
			ans++
			continue
		}
		if ex[j] <= k {
			ans++
			j--
		}
	}
	fmt.Print(ans)
}


package main

import "fmt"

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


package main

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

func main() {
	z:= bufio.NewScanner(os.Stdin)
	z.Split(bufio.ScanWords)
	z.Scan()
	n, _:= strconv.Atoi(strings.TrimSpace(z.Text()))
	z.Scan()
	k, _:= strconv.Atoi(strings.TrimSpace(z.Text()))
	m, t := 0,0
	for i := 0; i < n; i++  {
		z.Scan()
		a,_ := strconv.Atoi(strings.TrimSpace(z.Text()))
		if a>m {
			m=a
		}
		t+=a
	}

	var o string
	if t - m <= k {
		o = "YES"
	} else {
		o = "NO"
	}
	fmt.Println(o)
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	r := make(map[int]bool, 1e5)
	fmt.Scan(&a, &b, &c)
	for i := 1; ; i++ {
		if c == a*10/b {
			fmt.Println(i)
			return
		}
		a = a * 10 % b
		if !r[a] {
			r[a] = true
		} else {
			break
		}
	}
	fmt.Println(-1)
}


package main

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

type caseInput struct {
	num int
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	return caseInput{readInt(scanner)}
}

type caseOutput struct {
	ops int
}

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

func solveCase(in caseInput) caseOutput {
	numStr := fmt.Sprintf("%d", in.num)
	root := int(math.Floor(math.Sqrt(float64(in.num))))
	for root > 0 {
		squareStr := fmt.Sprintf("%d", root*root)
		if len(lcs(numStr, squareStr)) == len(squareStr) {
			return caseOutput{len(numStr) - len(squareStr)}
		}
		root -= 1
	}
	return caseOutput{-1}
}

//	that's from rozetta code and seems to work
func lcs(a, b string) string {
	arunes := []rune(a)
	brunes := []rune(b)
	aLen := len(arunes)
	bLen := len(brunes)
	lengths := make([][]int, aLen+1)
	for i := 0; i <= aLen; i++ {
		lengths[i] = make([]int, bLen+1)
	}
	// row 0 and column 0 are initialized to 0 already

	for i := 0; i < aLen; i++ {
		for j := 0; j < bLen; j++ {
			if arunes[i] == brunes[j] {
				lengths[i+1][j+1] = lengths[i][j] + 1
			} else if lengths[i+1][j] > lengths[i][j+1] {
				lengths[i+1][j+1] = lengths[i+1][j]
			} else {
				lengths[i+1][j+1] = lengths[i][j+1]
			}
		}
	}

	// read the substring out from the matrix
	s := make([]rune, 0, lengths[aLen][bLen])
	for x, y := aLen, bLen; x != 0 && y != 0; {
		if lengths[x][y] == lengths[x-1][y] {
			x--
		} else if lengths[x][y] == lengths[x][y-1] {
			y--
		} else {
			s = append(s, arunes[x-1])
			x--
			y--
		}
	}
	// reverse string
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return string(s)
}

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

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

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

	solveSequential(scanner, writer)
}

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

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

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


package main

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

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

	var n string
	fmt.Fscan(reader, &n)

	mp := make(map[string]int)
	mp["0"] = 2
	mp["1"] = 7
	mp["2"] = 2
	mp["3"] = 3
	mp["4"] = 3
	mp["5"] = 4
	mp["6"] = 2
	mp["7"] = 5
	mp["8"] = 1
	mp["9"] = 2

	fmt.Println(mp[string(n[0])] * mp[string(n[1])])

}


package main

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

func main() {
	b := make([][]rune, 3)
	for i := 0; i < 3; i++ {
		b[i] = []rune(nextWord())
	}
	xc, oc, xw, ow := 0, 0, 0, 0
	for i := 0; i < 3; i++ {
		if b[i][0] == b[i][1] && b[i][1] == b[i][2] {
			if b[i][0] == 'X' {
				xw++
			} else if b[i][0] == '0' {
				ow++
			}
		}
		if b[0][i] == b[1][i] && b[1][i] == b[2][i] {
			if b[0][i] == 'X' {
				xw++
			} else if b[0][i] == '0' {
				ow++
			}
		}
	}
	if b[0][0] == b[1][1] && b[1][1] == b[2][2] {
		if b[0][0] == 'X' {
			xw++
		} else if b[0][0] == '0' {
			ow++
		}
	}
	if b[0][2] == b[1][1] && b[1][1] == b[2][0] {
		if b[0][2] == 'X' {
			xw++
		} else if b[0][2] == '0' {
			ow++
		}
	}
	for y := 0; y < 3; y++ {
		for x := 0; x < 3; x++ {
			if b[y][x] == 'X' {
				xc++
			} else if b[y][x] == '0' {
				oc++
			}
		}
	}
	if xc != oc && xc != oc + 1 {
		printf("illegal\n")
	} else if xw > 0 && ow > 0 {
		printf("illegal\n")
	} else if xw > 0 {
		if xc == oc {
			printf("illegal\n")
		} else {
			printf("the first player won\n")
		}
	} else if ow > 0 {
		if xc == oc + 1 {
			printf("illegal\n")
		} else {
			printf("the second player won\n")
		}
	} else if xc + oc == 9 {
		printf("draw\n")
	} else if oc == xc {
		printf("first\n")
	} else {
		printf("second\n")
	}
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}


package main

import (
	"fmt"
)

func main() {
	var (
		given  int
		left   int
		rite   int
		maxs   int
		mins   int
		powers uint
	)
	fmt.Scanf("%d %d %d", &given, &left, &rite)

	powers = 0
	for i := 0; i < left; i++ {
		mins += 1 << powers
		powers++
	}
	mins += given - left

	powers = 0
	for i := 0; i < rite; i++ {
		maxs += 1 << powers
		powers++
	}
	maxs += (given - rite) * (1 << (powers - 1))
	fmt.Printf("%d %d", mins, maxs)

}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t,s,count,anc int

	fmt.Fscan(in, &t)
	for i := 0;i < t;i++{
		val := 9
		count = 1
		fmt.Fscan(in, &s)
		for s > 0{
			if s < 10 && val > s{
				anc += s*count
				s = 0
			}else{
				s -= val
				anc += val*count
				val--
				count *= 10
			}
		}
		fmt.Println(anc)
		anc = 0
	}
}


package main

import "fmt"

func main() {
	var w, h, k int

	fmt.Scanf("%d %d %d", &w, &h, &k)

	r := 0
	for i := 0; i < k; i++ {
		c := 2*(w+h) - 4
		r += c
		h -= 4
		w -= 4
	}

	fmt.Println(r)
}


package main

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

func Abs(x int) int {
	switch {
	case x < 0:
		return -x
	case x == 0:
		return 0
	}
	return x
}

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

func Scan(args ...interface{}) (e error)             { _, e = fmt.Fscan(in, args...); return }
func Scanf(ft string, args ...interface{}) (e error) { _, e = fmt.Fscanf(in, ft, args...); return }
func Scanln(args ...interface{}) (e error)           { _, e = fmt.Fscanln(in, args...); return }
func Print(args ...interface{})                      { out.WriteString(fmt.Sprint(args...)) }
func Printf(ft string, args ...interface{})          { out.WriteString(fmt.Sprintf(ft, args...)) }
func Println(args ...interface{})                    { out.WriteString(fmt.Sprintln(args...)) }

var (
	dataIn = "data.in"
	in     = bufio.NewReader(os.Stdin)
	//in, _ = os.Open(dataIn)
	out = bufio.NewWriter(os.Stdout)
)

var n int64

func bis(num int64) int64 {
	l := int64(1)
	r := int64(14142136)
	for l <= r {
		mid := (l + r) >> 1
		if mid*(mid+1)/2 > num {
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	return r
}

func solve() {
	m := bis(n)
	if n == m*(m+1)/2 {
		Println(m)
	} else {
		Println(n - m*(m+1)/2)
	}
}

func main() {
	defer out.Flush()
	for Scan(&n) != io.EOF {
		solve()
		out.Flush()
	}
	return
}


package main

import (
	"fmt"
)

var (
	colours = []byte("RGBYW")
	numbers = []byte("12345")
)

func bits(x int) (ans int) {
	for x > 0 {
		x &= (x - 1)
		ans++
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	cards := make([]string, n)
	for i := range cards {
		fmt.Scan(&cards[i])
	}
	res := 10
	for c := 0; c < 1 << 5; c++ {
		for nu := 0; nu < 1 << 5; nu++ {
			if bits(c) + bits(nu) > res {
				continue
			}
			know := make(map[byte]bool)
			for i := 0; i < 5; i++ {
				if c & (1 << uint(i)) != 0 {
					know[colours[i]] = true
				}
				if nu & (1 << uint(i)) != 0 {
					know[numbers[i]] = true
				}
			}
			var (
				nothing = make(map[string]bool)
				knowNu = make(map[byte]map[byte]bool)
				knowC = make(map[byte]map[byte]bool)
			)
			good := true
			for _, card := range cards {
				if !know[card[0]] && !know[card[1]] {
					nothing[card] = true
					if len(nothing) > 1 {
						good = false
						break
					}
				} else if !know[card[0]] {
					m := knowNu[card[1]]
					if m == nil {
						m = make(map[byte]bool)
						knowNu[card[1]] = m
					}
					m[card[0]] = true
					if len(m) > 1 {
						good = false
						break
					}
				} else if !know[card[1]] {
					m := knowC[card[0]]
					if m == nil {
						m = make(map[byte]bool)
						knowC[card[0]] = m
					}
					m[card[1]] = true
					if len(m) > 1 {
						good = false
						break
					}
				}
			}
			if good {
				res = bits(c) + bits(nu)
			}
		}
	}
	fmt.Println(res)
}


package main

import (
	"fmt"
	"strconv"
)

func isPalindrom(s string) bool {
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

func solve(s string) string {
	for c := 'a'; c <= 'z'; c++ {
		for i := 0; i <= len(s); i++ {
			t := s[:i] + strconv.QuoteRuneToASCII(c)[1:2] + s[i:]
			//fmt.Scanf("%s", &t)
			if isPalindrom(t) {
				return t
			}
		}
	}
	return "NA"
}

func main() {
	var s string
	fmt.Scanf("%s", &s)
	fmt.Printf("%s", solve(s))
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF148D(_r io.Reader, _w io.Writer) {
	var W, B int
	Fscan(_r, &W, &B)
	dp := make([][][2]float64, W+1)
	for i := range dp {
		dp[i] = make([][2]float64, B+1)
		for j := range dp[i] {
			dp[i][j] = [2]float64{-1, -1}
		}
	}
	var f func(w, b, who int) float64
	f = func(w, b, who int) (res float64) {
		if w <= 0 {
			if who == 0 {
				return 0
			}
			return 1
		}
		if b <= 0 {
			return 1
		}
		dv := &dp[w][b][who]
		if *dv != -1 {
			return *dv
		}
		defer func() { *dv = res }()
		if who == 0 {
			return (float64(w) + float64(b)*(1-f(w, b-1, 1))) / float64(w+b)
		}
		p := (float64(w)*f(w-1, b-1, 0) + float64(b-1)*f(w, b-2, 0)) / float64(w+b-1)
		return (float64(w) + float64(b)*(1-p)) / float64(w+b)
	}
	Fprintf(_w, "%.10f", f(W, B, 0))
}

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


package main

import "fmt"

func main() {
    var a, b, c int
    fmt.Scan(&a, &b, &c)
    if c == 0  {
        if a == b {
            fmt.Print("YES")
        } else {
            fmt.Print("NO")
        }
        return
    }
    if (b-a)%c == 0 && (b-a)/c >= 0 {
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}


package main

import "fmt"

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

	if n < m {
		fmt.Print(-1)
		return
	}

	step := n / 2
	left := n % 2
	exchange := false
	for (step+left)%m != 0 {
		if exchange {
			step -= 1
			exchange = false
		}
		left += 1
	}

	fmt.Print(step + left)
}


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

func correct(s, t string) bool {
    lens := len(s)
    lent := len(t)
    if lens != lent {
        return false
    }

    for i := 0; i < lens; i++ {
        if s[i] != t[lens-i-1] {
            return false
        }
    }

    return true
}

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

    if correct(s, t) {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}


// Try Codeforces
// author: Leonrdone @ NEETSDKASU
package main

import (
    "fmt"
    "sort"
)

type Foo []int64
func (f Foo) Len() int { return len(f) }
func (f Foo) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
func (f Foo) Less(i, j int) bool { return f[i] < f[j] }

func main() {
    var n, k int
    var m int64
    fmt.Scan(&n, &k, &m)
    xs := make([]int64, k)
    for i := range xs {
        fmt.Scan(&xs[i])
    }
    sum := int64(0)
    for _, x := range xs {
        sum += x
    }
    sort.Sort(Foo(xs))
    ans := int64(0)
    for i := 0; i <= n; i++ {
        altm := sum * int64(i)
        if altm > m {
            break
        }
        tmp := int64((k + 1) * i)
        p := int64(n - i)
        for _, x := range xs[:k-1] {
            w := p
            for altm + w * x > m {
                w--
            }
            altm += w * x
            tmp += w
        }
        for altm + p * xs[k-1] > m {
            p--
        }
        altm += p * xs[k-1]
        tmp += p * 2
        if tmp > ans {
            ans = tmp
        }
    }
    fmt.Println(ans)
}


package main

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

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

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

	n := nextInt()
	x := make([]int, 4)

	for i := 0; i < n; i++ {
		x[i] = nextInt()
	}

	switch n {
	case 0:
		x[0], x[1], x[2], x[3] = 1, 1, 3, 3
		printf("YES\n%d\n%d\n%d\n%d\n", x[0], x[1], x[2], x[3])
	case 1:
		x[1], x[2], x[3] = x[0], x[0] * 3, x[0] * 3
		printf("YES\n%d\n%d\n%d\n", x[1], x[2], x[3])
	case 2:
		if x[1] < x[0] {
			x[0], x[1] = x[1], x[0]
		}

		x[2], x[3] = 4 * x[0] - x[1], 3 * x[0]
		if x[2] > 0 {
			printf("YES\n%d\n%d\n", x[2], x[3])
		} else {
			println("NO")
		}
	case 3:
		sort.Ints(x[0:3])
		ok := false

		if x[2] % 3 == 0 && x[0] + x[1] == 4 * (x[2]/3) {
			x[3] = x[2] / 3
			ok = true
		}
		// println(x)

		if x[1] + x[2] == 4 * x[0] {
			x[3] = 3 * x[0]
			ok = true
		}

		if x[2] == x[0] * 3 {
			x[3] = x[0] * 4 - x[1]
			if x[3] >= x[0] {
				ok = true
			}
		}

		if ok {
			printf("YES\n%d\n", x[3])
		} else {
			println("NO")
		}

	case 4:
		sort.Ints(x)

		if isSpecial(x) {
			println("YES")
		} else {
			println("NO")
		}
	}

	// println(n, x)
}

func isSpecial(x []int) bool {
	median := x[3] - x[0]

	if median * 2 == (x[1]+x[2]) && median * 4 == (x[0]+x[1]+x[2]+x[3]) {
		return true
	}

	return false
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

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

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

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


package main

import (
	"fmt"
)

func main() {
	var a [6]int
	var result int
	for i := 0; i < 6; i++ {
		fmt.Scan(&a[i])
	}
	start := a[2]*2 - 1
	for ; a[0]+a[4] > 0; {
		if a[1] > 0 {
			start += 1
			a[1] -= 1
		} else if a[1] == 0 {
			a[1] -= 1
			a[0] -= 1
		} else {
			start -= 1
			a[0] -= 1
		}

		if a[3] > 0 {
			start += 1
			a[3] -= 1
		} else if a[3] == 0 {
			a[3] -= 1
			a[4] -= 1
		} else {
			start -= 1
			a[4] -= 1
		}
		result += start
	}
	fmt.Println(result)
}


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

  rowNum, colNum := int(getI()), int(getI())
  grid := make([][]byte, rowNum)
  for r := 0; r < rowNum; r++ {
    scanner.Scan()
    grid[r] = []byte(scanner.Text())
  }
  dr, dc := []int{ -1, 0, 1, 0}, []int{ 0, 1, 0, -1 }
  result := 0
  for r := 0; r < rowNum; r++ {
    for c := 0; c < colNum; c++ {
      if grid[r][c] == 'W' {
        for i := 0; i < 4; i++ {
          R, C := r+dr[i], c+dc[i]
          if R >= 0 && R < rowNum && C >= 0 && C < colNum {
            if grid[R][C] == 'P' {
              result++
              break
            }
          }
        }
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}


package main

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

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

var n, m int
var vType []Type
var edges [][]int

func main() {
	defer out.Flush()
	fmt.Fscan(in, &n, &m)
	vType = make([]Type, n)
	edges = make([][]int, n)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(in, &a, &b)
		a--
		b--
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	if solve() {
		fmt.Fprintln(out, "Yes")
		for v := range vType {
			fmt.Fprint(out, string('a'+vType[v]-1))
		}
		fmt.Fprintln(out)
	} else {
		fmt.Fprintln(out, "No")
	}
}

func solve() bool {
	for v := range edges {
		if len(edges[v]) == n-1 {
			vType[v] = B
		}
	}
	for v := range vType {
		if vType[v] == UNSEEN {
			mark(v, A)
			break
		}
	}
	for v := range vType {
		if vType[v] == UNSEEN {
			mark(v, C)
			break
		}
	}
	var a, b, c int
	for v := range vType {
		switch vType[v] {
		case UNSEEN:
			return false
		case A:
			a++
		case B:
			b++
		case C:
			c++
		}
	}
	for v := range vType {
		if vType[v] == A && len(edges[v]) != a-1+b {
			return false
		}
		if vType[v] == C && len(edges[v]) != c-1+b {
			return false
		}
	}
	return true
}

func mark(v int, t Type) {
	if vType[v] != UNSEEN {
		return
	}
	vType[v] = t
	for _, u := range edges[v] {
		mark(u, t)
	}
}

type Type int

const (
	UNSEEN Type = iota
	A
	B
	C
)


package main
import "fmt"

func main(){
    var n int
    fmt.Scan(&n)
    fmt.Println(n/2+1)
}


package main

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

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

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

	n := nextInt()
	s := next()
	count := 0

	for i := 0; i < n; i++ {
		if s[i] == '1' {
			count++
		} else {
			if i < n {
				count++
			}
			break
		}
	}

	println(count)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

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

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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


package main
import
(
  "fmt"
  // "math"
)
func main(){
 var i int
 fmt.Scanf("%d" , &i)
 // temp:= i
 x :=1
 count := 0
 var s []int
 if(i>81){
   x =x-81
 }

 for ;x<i;x++{
   if ((i-x)>81){
     continue
   }
   temp := x
    rs := (i-x)
    // temp2 :=1
    // fmt.Println(x)
    sum :=0
   for ;temp>0;temp/=10{

    // fmt.Println(mult)
  //  var digits [] int

     xlast := temp%10
     sum +=xlast

    //  res := temp + xlast
    //  fmt.Println(temp,xlast)

   }
   if sum==rs{
     s = append(s,x)
        count ++
   }
 }
 if (count == 0){
fmt.Println(0)
}else
{
  fmt.Println(count)
  for x:=0;x<count;x++{
    fmt.Println(s[x])
  }
}
}


package main
import (
	"fmt"
)
func main() {
	var n,m int
	min,c := 0,0
	fmt.Scan(&n,&m)
	if n<m {
		min = n
	} else {min = m}
	for i:=0; i<=min;i++ {
		for j:=0;j<=min;j++ {
			if (i*i+j)==n && (i+j*j)==m {
				c++
			}
		}
	}
	fmt.Println(c)
}


package main
import "fmt"
func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var x string
		fmt.Scanf("%s\n", &x)
		dig := int(x[0] - '0')
		fmt.Println((dig - 1) * 10 + len(x) * (len(x) + 1) / 2)
	}
}


package main

import "fmt"

func main() {
    var n int
    var s string
    fmt.Scan(&n)
    fmt.Scan(&s)
    lucky, first, second := true, 0, 0
    for i := 0; i < n; i++ {
        if lucky {
            if (s[i] != '4') && (s[i] != '7') { lucky = false }
            if i < (n/2) {
                first += int(s[i]-'0')
            } else {
                second += int(s[i]-'0')
            }
        }
    }
    if first != second { lucky = false }
    if lucky { fmt.Println("YES") } else { fmt.Println("NO") }
}


package main

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

func numSteps(st int) int {
	num := st / 5
	if st%5 > 0 {
		num++
	}
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	st, _ := strconv.Atoi(scanner.Text())
	fmt.Println(numSteps(st))
}


package main

import (
    "sort"
    "fmt"
)

func main() {
    a := make([]int, 10)
    for i := 0; i < 6; i++ {
        var x int
        fmt.Scan(&x)
        a[x]++
    }
    sort.Ints(a)
    if a[len(a)-1] == 6 {
        fmt.Println("Elephant")
    } else if a[len(a)-1] == 5 {
        fmt.Println("Bear")
    } else if a[len(a)-1] == 4 {
        if a[len(a)-2] == 2 {
            fmt.Println("Elephant")
        } else {
            fmt.Println("Bear")
        }
    } else {
        fmt.Println("Alien")
    }
}


package main

import (
	"fmt"
)

func main()  {
	var strInput string
	fmt.Scan(&strInput)
	startIndex := 97
	element := 0
	sum := 0

	for _, s := range strInput {
		if int(s) > startIndex {
			element = int(s) - startIndex
		} else {
			element = startIndex - int(s)
		}
		if (element > 13 ) {
			element = 26 - element
		}
		startIndex = int(s)
		sum = sum + element
	}
	fmt.Println(sum)
}


package main
import (
	"fmt"
)
func main() {
	//var a,b,c,d int
	var s1,s2,t1,t2 int
	fmt.Scanf("%d:%d\n",&s1,&s2)
	fmt.Scanf("%d:%d",&t1,&t2)
	//fmt.Println(s1,s2,t1,t2)
	s:=s1*60+s2
	s-=t2
	s-=t1*60
	if s<0 {
		s+=24*60
	}
	fmt.Printf("%02d:%02d\n",s/60,s%60)

}


package main

import (
	"fmt"
)

// 1200
// 28.05.2020
// https://codeforces.com/problemset/problem/353/A

func main() {
	var n int
	fmt.Scanln(&n)

	xs := make([]int, n)
	ys := make([]int, n)

	var sumx, sumy int
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Scanln(&x, &y)
		xs[i] = x
		ys[i] = y

		sumx += x
		sumy += y
	}
	if sumx%2 == 0 && sumy%2 == 0 {
		fmt.Println("0")
		return
	}
	if sumx%2 == 1 && sumy%2 == 1 {
		for i := 0; i < n; i++ {
			if xs[i]%2 != ys[i]%2 {
				fmt.Println("1")
				return
			}
		}
	}
	fmt.Println("-1")
}


package main

import (
	"fmt"
	"math"
)

var pos [40000001]int

func main() {
	var n int64
	fmt.Scanf("%d", &n)
	if n == 0 {
		fmt.Printf("1")
		return
	}
	ans := 4
	for x := int64(1); x < n; x++ {
		pos[x] = int(math.Sqrt(float64(n*n - x*x)))
	}
	for x := int64(1); x < n; x++ {
		if int(x) != pos[pos[x]] {
			ans += 8
		} else {
			ans += 4
		}
	}
	fmt.Printf("%d", ans)
}


package main

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

//aのb乗をします O(log b)
func pow(a int, b int) int {
	total := 1
	tmp := a
	for b > 0 {
		if b%2 == 1 {
			total *= tmp
		}
		b /= 2
		tmp *= tmp
	}
	return total
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	mx := 0
	for k := uint(1); ; k++ {
		l := ((1 << k) - 1) * (1 << (k - 1))
		if l > N {
			break
		}
		if N%l == 0 {
			mx = l
		}
	}
	fmt.Println(mx)

}

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 k, n uint64
func main() {
	fmt.Scan(&n, &k)
	if k == 1 {
		fmt.Print(n)
	} else {
		var i uint = 1
		var s uint64
		for s = 1; (s << 1) <= n; i++ {
			s <<= 1;
		}
		fmt.Print((uint64(1) << i) - 1)
	}
}


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	x := []int{}
	for _, v := range s {
		vv, _ := strconv.Atoi(v)
		x = append(x, vv)
	}
	floors := x[1] - x[0]
	if floors < 0 {
		floors = -floors
	}

	elevExtra := x[2] - x[0]
	if elevExtra < 0 {
		elevExtra = -elevExtra
	}

	elevTime := ((floors + elevExtra) * x[4]) + (3 * x[5])
	stairTime := floors * x[3]
	if elevTime <= stairTime {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


package main

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

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

	var h,m int
	var start ,end int
	fmt.Fscanf(buf, "%d:%d\n", &h,&m)
	start = h*60+m
	fmt.Fscanf(buf, "%d:%d\n", &h,&m)
	end = h*60+m
	start = (start+end)/2
	h = start/60
	m =start%60
	fmt.Printf("%02d:%02d\n",h,m)

}


package main

import (
	"fmt"
	"math"
)

func main() {
	var m, n int64
	fmt.Scan(&n, &m)
	min := math.Max(float64(n-2*m), 0.0)

	connectedCount := int64(0)
	usedEdges := int64(0)
	for i := int64(1); i < n; i++ {
		if usedEdges >= m {
			break
		}
		usedEdges += i
		// The first edge connects two vertices, otherwise, every new vertex can use i edges.
		if connectedCount == 0 {
			connectedCount = 2
		} else {
			connectedCount++
		}
	}
	fmt.Println(min, n-connectedCount)
}


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

func main() {
    var s string
    fmt.Scan(&s)
    nSum := 0
    for i := 0; i < len(s); i++ { // for every Q in s
        if s[i] != 'Q' { // first Q
            continue
        }

        for j := i + 1; j < len(s); j++ { // for every Q after s[i]
            if s[j] == 'Q' { // second Q
                for k := i + 1; k < j; k++ {
                    if s[k] == 'A' {
                        nSum += 1
                    }
                }
            }
        }

    }

    fmt.Println(nSum)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var r, g, b, i int32
	var maxVal int32
	fmt.Scan(&r, &g, &b)
	minVal := min(r, g, b)
	maxVal = r/3 + g/3 + b/3
	minAll := min(int32(2), minVal, math.MaxInt32)
	for i = 1; i <= minAll; i++ {
		maxVal = max(maxVal, ((r-i)/3+(g-i)/3+(b-i)/3)+i, math.MinInt32)
	}
	fmt.Printf("%v", maxVal)
}

func min(a int32, b int32, c int32) int32 {
	if a <= b && a <= c {
		return a
	} else if b <= a && b <= c {
		return b
	} else {
		return c
	}
}

func max(a int32, b int32, c int32) int32 {
	if a >= b && a >= c {
		return a
	} else if b >= a && b >= c {
		return b
	} else {
		return c
	}
}


package main

import (
	"fmt"
	"os"
)

func main() {
	num := 0
	fmt.Scan(&num)
	primeMap := map[int]int{}
	if num == 1 {
		fmt.Println("1 0")
		os.Exit(0)
	}

	for i := 2; i <= 1000; i++ {
		for num%i == 0 {
			num, primeMap[i] = num/i, primeMap[i]+1
		}
	}
	if num > 1 {
		primeMap[num]++
	}

	max := 0
	for _, v := range primeMap {
		if v > max {
			max = v
		}
	}

	finalValue := 1
	for k := range primeMap {
		finalValue *= k
	}

	allTheSame := true
	for _, v := range primeMap {
		if v != max {
			allTheSame = false
		}
	}

	step := 0
	tmp := 1
	for tmp < max {
		step, tmp = step+1, tmp*2
	}

	// In what condition, we need increase step?
	// 1. tmp > max, which means we need mul the num, does not matter whether "all the same"
	// 2. tmp == max, but is not "all the same", which means we still mul once
	if (tmp > max) || ((tmp == max) && !allTheSame) {
		step++
	}
	fmt.Println(finalValue, step)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF101C(in io.Reader, out io.Writer) {
	var x, y [3]int64
	for i := 0; i < 3; i++ {
		Fscan(in, &x[i], &y[i])
	}
	d := x[2]*x[2] + y[2]*y[2]
	for i := 0; i < 4; i++ {
		x[0], y[0] = y[0], x[0]
		y[0] = -y[0]
		dx, dy := x[1]-x[0], y[1]-y[0]
		d1, d2 := dx*x[2]+dy*y[2], dx*y[2]-dy*x[2]
		if d == 0 && dx == 0 && dy == 0 || d > 0 && d1%d == 0 && d2%d == 0 {
			Fprint(out, "YES")
			return
		}
	}
	Fprint(out, "NO")
}

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


package main

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

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

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

	n := nextInt()
	s := next()
	// println(s)

	for i := 0; i < n; i++ {
		if s[i] == '*' {
			length := 0

			for j := i + 1; j < n; j++ {
				if s[j] == '*' {
					length = j - i
					// println(i, length)

					if i+length*4 < n &&
						s[i+length*2] == '*' &&
						s[i+length*3] == '*' &&
						s[i+length*4] == '*' {
						println("yes")
						return
					}
				}
			}
		}
	}

	println("no")
}

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

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	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 printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}


package main

import "fmt"

// max(fn) <= p
func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}

func sum(a []int) int {
	nSum := 0
	for _, v := range a {
		nSum += v
	}

	return nSum
}

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

	return b - a
}

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

	if n == 1 {
		fmt.Println("360")
		return
	}

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

	// enum every possible
	nMin := 360
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			//fmt.Println("i", i, "j", j)
			f1 := sum(a[i:j])
			f2 := sum(a[j:n+i])
			d := diff(f1, f2)
			nMin = min(nMin, d)
		}
	}

	fmt.Println(nMin)
}


package main

import (
	"fmt"
)

func main() {
	inputString := ""
	fmt.Scanf("%s", &inputString)
	l := len(inputString)
	if l==1 {
		fmt.Println("YES")
		return
	} else if l==2 && inputString[0]!=inputString[1] {
		fmt.Println("YES")
		return
	} else if l==3 && inputString[0]!=inputString[1] && inputString[0]==inputString[2] {
		fmt.Println("YES")
		return
	}
	ld := l/2
	res := 0
	for i := 0; i < ld; i++ {
		if inputString[i] != inputString[l-1-i] {
			res++
			if res > 1 {
				fmt.Println("NO")
				return
			}
		}
	}
	if res == 1 {
		fmt.Println("YES")
	} else if res == 0 && l%2 == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

package main

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

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

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

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

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

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

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

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

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

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

var (
	n, m int

	M, MM [1000 + 50]int
)

func main() {
	n, m = ReadInt2()

	q := n / m
	for i := 0; i < m; i++ {
		M[i] = q
	}
	for i := 1; i <= n%m; i++ {
		M[i]++
	}

	for i := 0; i < m; i++ {
		to := (i * i) % m
		MM[to] += M[i]
	}

	ans := int64(0)
	ans += int64(MM[0]) * int64(MM[0])
	for i := 1; i < m; i++ {
		ans += int64(MM[i]) * int64(MM[m-i])
	}
	fmt.Println(ans)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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


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

func main() {
	var a,b,c,d int
	fmt.Scan(&a,&b,&c)
	d=c*b+(a-1)*b+(c-1)*(a-1)
	fmt.Println(d)
}


package main

import (
  "fmt"
  "sort"
)

func main() {
  var n, k int
  fmt.Scanf("%d%d\n", &n, &k)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scanf("%d", &a[i])
  }
  fmt.Scanf("\n")
  b := make([]int, k)
  for i := 0; i < k; i++ {
    fmt.Scanf("%d", &b[i])
  }
  sort.Ints(b)
  for i := 0; i < n; i++ {
    if a[i] == 0 {
      a[i] = b[k - 1]
      k--
    }
  }
  for i := 1; i < n; i++ {
    if a[i - 1] > a[i] {
      fmt.Printf("Yes\n")
      return
    }
  }
  fmt.Printf("No\n")
  return
}


package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	for i := 1; m-i >= 0; i++ {
		m = m - i
		if i == n {
			i = 0
		}
	}
	fmt.Println(m)
}


package main

import (
	"fmt"
)

func main() {
	var b, g, n int
	fmt.Scan(&b, &g, &n)
	ans := 0
	for i := 0; i <= n; i++ {
		if i <= b && n-i <= g {
			ans++
		}
	}
	fmt.Println(ans)
}