We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's 1 coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in k days. He decided to spend these last days with helping poor people. After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too. Your task is to find the difference between richest and poorest persons wealth after k days. Note that the choosing at random among richest and poorest doesn't affect the answer.

The first line of the input contains two integers n and k (1 ≤ n ≤ 500 000, 0 ≤ k ≤ 109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement. The second line contains n integers, the i-th of them is ci (1 ≤ ci ≤ 109) — initial wealth of the i-th person.

Print a single line containing the difference between richest and poorest peoples wealth.

NoteLets look at how wealth changes through day in the first sample.  [1, 1, 4, 2]  [2, 1, 3, 2] or [1, 2, 3, 2] So the answer is 3 - 1 = 2In second sample wealth will remain the same for each person.

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		} else if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		} else if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}

	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]
		x := int((int64(l.ppl)*r.cash - l.cash*int64(r.ppl)) / int64(r.ppl+l.ppl))
		if x > k {
			x = k
		} else if x < 0 {
			x = 0
		}
		l.cash += int64(x)
		r.cash -= int64(x)
		k -= x
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		} else if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		} else if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}

	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]
		x := int((int64(l.ppl)*r.cash - l.cash*int64(r.ppl)) / int64(r.ppl+l.ppl))
		if x > k {
			x = k
		} else if x < 0 {
			x = 0
		}
		l.cash += int64(x)
		r.cash -= int64(x)
		k -= x
	}

	l := p[0]
	r := p[len(p)-1]
	pst, pst1 := l.avg()
	rst, rst1 := r.avg()
	var ans []int
	ans = append(ans, pst, pst1, rst, rst1)
	sort.Ints(ans)
	fmt.Println(ans[3] - ans[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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	k := int64(readInt())

	c := make([]int, n)
	sum := 0
	for i := range c {
		c[i] = readInt()
		sum = (sum + c[i]) % n
	}
	sort.Ints(c)

	rich := c[n-1]
	passed := int64(0)
	for i := n - 1; i > 0; i-- {
		if c[i] == c[i-1] {
			continue
		}
		to := int64(n-i) * int64(rich-c[i-1])
		if to+passed >= k {
			rich -= int((k - passed) / int64(n-i))
			break
		}
		passed += to
		rich = c[i-1]
	}

	poor := c[0]
	passed = 0
	for i := 0; i < n-1; i++ {
		if c[i] == c[i+1] {
			continue
		}
		to := int64(i+1) * int64(c[i+1]-poor)
		if to+passed >= k {
			poor += int((k - passed) / int64(i+1))
			break
		}
		passed += to
		poor = c[i+1]
	}

	if rich <= poor {
		if sum == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(1)
		}
	} else {
		fmt.Println(rich - poor)
	}
}

package main

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

func Init() {
}

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

	ans := GetHigh(C, K) - GetLow(C, K)
	if ans > 0 {
	  io.Println(ans)
	  return
	}

	sum := int64(0)
	for _, v := range C {
	  sum += v
	}
	if sum % int64(N) == 0 {
	  io.Println(0)
	} else {
	  io.Println(1)
	}
}

func GetHigh(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000)
  good := R
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v > M {
        sum += v - M
      }
    }
    if sum <= K {
      R = M - 1
      good = M
    } else {
      L = M + 1
    }
  }
  return good
}

func GetLow(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000)
  good := L
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v < M {
        sum += M - v
      }
    }
    if sum <= K {
      L = M + 1
      good = M
    } else {
      R = M - 1
    }
  }
  return good
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}

	if k > 0 && len(p) == 2 {
		var sum int64
		for i := 0; i < n; i++ {
			sum += int64(v[i])
		}
		avg := sum / int64(n)

		l := &p[0]
		r := &p[1]

		tr := r.diff(avg)
		tl := l.diff(avg)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	var sum int64
	for i := 0; i < n; i++ {
		sum += int64(v[i])
	}
	avg := int(sum / int64(n))
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(max64(r2.cash, int64(avg)))
		tl := l.diff(min64(l2.cash, int64(avg)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(max64(l.cash, int64(avg)))
		tl := l.diff(min64(r.cash, int64(avg)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	// var sum int64
	// for i := 0; i < n; i++ {
	// 	sum += int64(v[i])
	// }
	// avg := int(sum / int64(n))
        // fmt.Println("avg",avg)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		fmt.Printf("%+v\n", p)
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		// tr := r.diff(max64(r2.cash, int64(avg)))
		// tl := l.diff(min64(l2.cash, int64(avg)))
		tr := r.diff( r2.cash )
		tl := l.diff( l2.cash )
		t := min64(min64(tr, tl), int64(k))
		fmt.Println(k, tl, tr)

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
                        fmt.Println("break")
			break
		}
	}
	fmt.Printf("%+v (last),k=%v\n", p,k)
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		// tr := r.diff(max64(l.cash, int64(avg)))
		// tl := l.diff(min64(r.cash, int64(avg)))
		tr := r.diff( l.cash /int64(l.ppl))
		tl := l.diff( r.cash /int64(r.ppl))
		t := min64(min64(tr, tl), int64(k))
                	fmt.Println(k, tl, tr)

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, t1 := l.avg()
	t2, rst := r.avg()
	fmt.Println(rst - pst)
        fmt.Println("dbg",pst, t1,t2,rst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	var sum int64
	for i := 0; i < n; i++ {
		sum += int64(v[i])
	}
	avg := int(sum / int64(n))
	avgU := avg
	if sum%int64(n) != 0 {
		avgU++
	}
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(max64(r2.cash, int64(avgU)))
		tl := l.diff(min64(l2.cash, int64(avg)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(max64(l.cash, int64(avgU)))
		tl := l.diff(min64(r.cash, int64(avg)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	var sum int64
	for i := 0; i < n; i++ {
		sum += int64(v[i])
	}
	avg := int(sum / int64(n))
	avgU := avg
	if sum%int64(n) != 0 {
		avgU++
	}
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(max64(r2.cash, int64(avg)))
		tl := l.diff(min64(l2.cash, int64(avgU)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(max64(l.cash, int64(avg)))
		tl := l.diff(min64(r.cash, int64(avgU)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	var sum int64
	for i := 0; i < n; i++ {
		sum += int64(v[i])
	}
	avg := int(sum / int64(n))
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(max64(l.cash, int64(avg)))
		tl := l.diff(min64(r.cash, int64(avg)))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(l.cash)
		tl := l.diff(r.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}

	if k > 0 && len(p) == 2 {
		var sum int64
		for i := 0; i < n; i++ {
			sum += int64(v[i])
		}
		avg := sum / int64(n)
		upd := int64(0)
		if sum%int64(n) != 0 {
			upd = 1
		}

		l := &p[0]
		r := &p[1]

		tr := r.diff(avg) - upd
		tl := l.diff(avg)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}
	if k > 0 && len(p) == 2 {
		var sum int64
		for i := 0; i < n; i++ {
			sum += int64(v[i])
		}
		avg := sum / int64(n)
		avgu := avg
		if sum%int64(n) != 0 {
			avgu++
		}

		l := &p[0]
		r := &p[1]

		tr := r.diff(avgu)
		tl := l.diff(avg)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type com struct {
	cash int64
	ppl  int
}

func (c com) diff(avg int64) int64 {
	x := int64(c.ppl) * avg
	if x > c.cash {
		return x - c.cash
	} else {
		return c.cash - x
	}
}
func (c com) avg() (int, int) {
	p := int64(c.ppl)
	eq := c.cash%p == 0
	x := int(c.cash / p)
	if eq {
		return x, x
	}
	return x, x + 1
}

func main() {
	n, k := getInt(), getInt()
	v := getNint(n)
	sort.Ints(v)

	p := make([]com, n) // unnecessary mem, but prob. is simpler with vector
	for i, c := range v {
		p[i].ppl = 1
		p[i].cash = int64(c)
	}
	for len(p) > 2 && k > 0 {
		l := &p[0]
		l2 := &p[1] // maybe == r2
		r2 := &p[len(p)-2]
		r := &p[len(p)-1]

		// tr := r.diff(max64(r2.cash, int64(avg)))
		// tl := l.diff(min64(l2.cash, int64(avg)))
		tr := r.diff(r2.cash)
		tl := l.diff(l2.cash)
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)

		if l.diff(l2.cash) == 0 {
			l2.cash += l.cash
			l2.ppl += l.ppl
			l.ppl = 0
		}
		if r.diff(r2.cash) == 0 {
			r2.cash += r.cash
			r2.ppl += r.ppl
			r.ppl = 0
		}
		if l.ppl == 0 {
			p = p[1:]
			t = 1
		}
		if r.ppl == 0 {
			p = p[:len(p)-1]
			t = 1
		}
		if t == 0 {
			break
		}
	}

	if k > 0 && len(p) == 2 {
		l := &p[0]
		r := &p[1]

		tr := r.diff(l.cash / int64(l.ppl))
		tl := l.diff(r.cash / int64(r.ppl))
		t := min64(min64(tr, tl), int64(k))

		l.cash += t
		r.cash -= t
		k -= int(t)
	}

	l := p[0]
	r := p[len(p)-1]
	pst, _ := l.avg()
	_, rst := r.avg()
	fmt.Println(rst - pst)
}

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 getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
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
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	k := readInt()

	c := make([]int, n)
	sum := 0
	for i := range c {
		c[i] = readInt()
		sum = (sum + c[i]) % n
	}
	sort.Ints(c)

	rich := c[n-1]
	passed := 0
	for i := n - 1; i > 0; i-- {
		if c[i] == c[i-1] {
			continue
		}
		to := (n - i) * (rich - c[i-1])
		if to+passed >= k {
			rich -= (k - passed) / (n - i)
			break
		}
		passed += to
		rich = c[i-1]
	}

	poor := c[0]
	passed = 0
	for i := 0; i < n-1; i++ {
		if c[i] == c[i+1] {
			continue
		}
		to := (i + 1) * (c[i+1] - poor)
		if to+passed >= k {
			poor += (k - passed) / (i + 1)
			break
		}
		passed += to
		poor = c[i+1]
	}

	if rich <= poor {
		if sum == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(1)
		}
	} else {
		fmt.Println(rich - poor)
	}
}

package main

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

func Init() {
}

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

	ans := GetHigh(C, K) - GetLow(C, K)
	if ans >= 0 {
	  io.Println(ans)
	} else {
	  io.Println(0)
	}
}

func GetHigh(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000000000)
  good := R
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v > M {
        sum += v - M
      }
    }
    if sum <= K {
      R = M - 1
      good = M
    } else {
      L = M + 1
    }
  }
  return good
}

func GetLow(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000000000)
  good := L
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v < M {
        sum += M - v
      }
    }
    if sum <= K {
      L = M + 1
      good = M
    } else {
      R = M - 1
    }
  }
  return good
}

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

func Init() {
}

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

	ans := GetHigh(C, K) - GetLow(C, K)
	if ans > 0 {
	  io.Println(ans)
	  return
	}

	sum := int64(0)
	for _, v := range C {
	  sum += v
	}
	if sum % int64(N) == 0 {
	  io.Println(0)
	} else {
	  io.Println(1)
	}
}

func GetHigh(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000000000)
  good := R
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v > M {
        sum += v - M
      }
    }
    if sum <= K {
      R = M - 1
      good = M
    } else {
      L = M + 1
    }
  }
  return good
}

func GetLow(C []int64, K int64) int64 {
  L := int64(0)
  R := int64(1000000000000000)
  good := L
  for L <= R {
    M := (L + R) / 2
    sum := int64(0)
    for _, v := range C {
      if v < M {
        sum += M - v
      }
    }
    if sum <= K {
      L = M + 1
      good = M
    } else {
      R = M - 1
    }
  }
  return good
}

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


A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation:  Select the subtree of the given tree that includes the vertex with number 1.  Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.

The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree.  The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).

Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	g[0] = append(g[0], -1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	var f func(v, fa int) (mi, mx int64)
	f = func(v, fa int) (mi, mx int64) {
		x := a[v]
		if len(g[v]) == 1 {
			return min(0, x), max(0, x)
		}
		for _, w := range g[v] {
			if w != fa {
				x, y := f(w, v)
				mi = min(mi, x)
				mx = max(mx, y)
			}
		}
		if mi < 0 {
			x -= mi
		}
		if mx > 0 {
			x -= mx
		}
		if x < 0 {
			mi += x
		} else {
			mx += x
		}
		return
	}
	x, y := f(0, -1)
	Fprint(_w, y-x)
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	g[0] = append(g[0], -1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	var f func(v, fa int) (mi, mx int64)
	f = func(v, fa int) (mi, mx int64) {
		x := a[v]
		if len(g[v]) == 1 {
			return min(0, x), max(0, x)
		}
		for _, w := range g[v] {
			if w != fa {
				x, y := f(w, v)
				mi = min(mi, x)
				mx = max(mx, y)
			}
		}
		x -= mi + mx
		if x < 0 {
			mi += x
		} else {
			mx += x
		}
		return
	}
	x, y := f(0, -1)
	Fprint(_w, y-x)
}

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

package main

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

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    dec, inc := Calc(nodes[1])
    io.Println(dec + inc)
}

type Node struct {
    next map[*Node]bool
    val int64
    delta int64
    moves int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func (this *Node) ActualValue() int64 {
    return this.val + this.delta
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Calc(u *Node) (int64, int64) {
    var dec, inc int64

    for v := range u.next {
        d, i := Calc(v)

        dec = Max(dec, d)
        inc = Max(inc, i)
    }

    val := u.val + inc - dec
    if val > 0 {
        return dec + val, inc
    } else {
        return dec, inc - val
    }
}

func Max(args ...int64) int64 {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    dec, inc := Calc(nodes[1])
    io.Println(dec + inc)
}

type Node struct {
    next map[*Node]bool
    val int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Calc(u *Node) (int64, int64) {
    var dec, inc int64

    for v := range u.next {
        d, i := Calc(v)

        dec = Max(dec, d)
        inc = Max(inc, i)
    }

    val := u.val + inc - dec
    if val > 0 {
        return dec + val, inc
    } else {
        return dec, inc - val
    }
}

func Max(args ...int64) int64 {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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"
	"bytes"
	"fmt"
    "math"
	"os"
)

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    Rec(nodes[1])
    io.Println(nodes[1].moves + Abs(nodes[1].ActualValue()))

//     _, _, ans := Calc(nodes[1])
//     io.Println(ans, nodes[1].val)

//     _, s := Calc2(nodes[1])
//     io.Println(s + Abs(nodes[1].val))

    // v, d, s := Calc(nodes[1])
    // io.Println(v, d, s)
}

type Node struct {
    next map[*Node]bool
    val int64
    delta int64
    moves int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func (this *Node) ActualValue() int64 {
    return this.val + this.delta
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Rec(u *Node) {
    // fmt.Println("+", u)

    // if len(u.next) == 0 {
    //     fmt.Println("-", u)
    //     return
    // }

    // lo := int64(math.MaxInt64)
    // hi := int64(math.MinInt64)

    var lo, hi int64

    for v := range u.next {
        Rec(v)

        u.delta += v.delta
        u.moves += v.moves

        lo = Min(lo, v.ActualValue())
        hi = Max(hi, v.ActualValue())
    }

    // fmt.Println(" ", lo, hi)
    u.moves += hi - lo
    u.delta -= hi + lo

    // fmt.Println("-", u)
}

func Calc2(u *Node) (int64, int64) {
    if len(u.next) == 0 {
        return 0, 0
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        d, s := Calc2(v)

        delta += d
        sum += s

        lo = Min(lo, v.val)
        hi = Max(hi, v.val)
    }

    // fmt.Println(u.val, delta)

    u.val += delta
    return delta - u.val, sum + hi - lo
}

func Calc(u *Node) (int64, int64, int64) {
    if len(u.next) == 0 {
        fmt.Println("DONE", u.val)
        return u.val, -u.val, Abs(u.val)
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        v, d, s := Calc(v)

        delta += d
        sum += s

        lo = Min(lo, v)
        hi = Max(hi, v)
    }

    fmt.Println("HERE", u.val, u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo)
    return u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo

    // fmt.Println(u.val, sum, lo, hi)
    // return hi - lo

//     nv := u.val + delta

//     delta -= nv
//     sum += Abs(nv)

//     return delta, sum
}

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

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

func Max(args ...int64) int64 {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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"
	"bytes"
	"fmt"
    "math"
	"os"
)

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    Rec(nodes[1])
    io.Println(nodes[1].moves + Abs(nodes[1].ActualValue()))

//     _, _, ans := Calc(nodes[1])
//     io.Println(ans, nodes[1].val)

//     _, s := Calc2(nodes[1])
//     io.Println(s + Abs(nodes[1].val))

    // v, d, s := Calc(nodes[1])
    // io.Println(v, d, s)
}

type Node struct {
    next map[*Node]bool
    val int64
    delta int64
    moves int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func (this *Node) ActualValue() int64 {
    return this.val + this.delta
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Rec(u *Node) {
    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        Rec(v)

        u.delta += v.delta
        u.moves += v.moves

        lo = Min(lo, v.ActualValue())
        hi = Max(hi, v.ActualValue())
    }

    u.moves += hi - lo
    u.delta -= hi + lo
}

func Calc2(u *Node) (int64, int64) {
    if len(u.next) == 0 {
        return 0, 0
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        d, s := Calc2(v)

        delta += d
        sum += s

        lo = Min(lo, v.val)
        hi = Max(hi, v.val)
    }

    // fmt.Println(u.val, delta)

    u.val += delta
    return delta - u.val, sum + hi - lo
}

func Calc(u *Node) (int64, int64, int64) {
    if len(u.next) == 0 {
        fmt.Println("DONE", u.val)
        return u.val, -u.val, Abs(u.val)
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        v, d, s := Calc(v)

        delta += d
        sum += s

        lo = Min(lo, v)
        hi = Max(hi, v)
    }

    fmt.Println("HERE", u.val, u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo)
    return u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo

    // fmt.Println(u.val, sum, lo, hi)
    // return hi - lo

//     nv := u.val + delta

//     delta -= nv
//     sum += Abs(nv)

//     return delta, sum
}

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

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

func Max(args ...int64) int64 {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    _, ans := Calc(nodes[1])
    io.Println(ans)
}

type Node struct {
    next map[*Node]bool
    val int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Calc(u *Node) (int64, int64) {
    var delta, sum int64

    for v := range u.next {
        d, s := Calc(v)

        delta += d
        sum += s
    }

    nv := u.val + delta

    delta -= nv
    sum += Abs(nv)

    return delta, sum

//     lo := u.val - sub
//     hi := u.val + add

//     fmt.Printf("add = %d, sub = %d, lo = %d, hi = %d\n", add, sub, lo, hi)

//     if lo > 0 {
//         sum += lo
//         sub += lo
//     }
//     if hi < 0 {
//         sum -= hi
//         add -= hi
//     }

//     fmt.Printf("  new add = %d, sub = %d\n", add, sub)

//     for v := range u.next {
//         sum += Calc(v, add, sub)
//     }

//     return sum
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func Init() {
}

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

    nodes := make([]*Node, N + 1)
    for i := 1; i <= N; i++ {
        nodes[i] = MakeNode()
    }

    for i := 1; i < N; i++ {
        A := io.NextInt()
        B := io.NextInt()

        nodes[A].next[nodes[B]] = true
        nodes[B].next[nodes[A]] = true
    }

    for i := 1; i <= N; i++ {
        V := io.NextLong()

        nodes[i].val = V
    }

    Rootify(nodes[1], nil)

    Rec(nodes[1])
    io.Println(nodes[1].moves + Abs(nodes[1].ActualValue()))

//     _, _, ans := Calc(nodes[1])
//     io.Println(ans, nodes[1].val)

//     _, s := Calc2(nodes[1])
//     io.Println(s + Abs(nodes[1].val))

    // v, d, s := Calc(nodes[1])
    // io.Println(v, d, s)
}

type Node struct {
    next map[*Node]bool
    val int64
    delta int64
    moves int64
}

func MakeNode() *Node {
    return &Node{
        next: make(map[*Node]bool),
    }
}

func (this *Node) ActualValue() int64 {
    return this.val + this.delta
}

func Rootify(u, p *Node) {
    delete(u.next, p)
    for v := range u.next {
        Rootify(v, u)
    }
}

func Rec(u *Node) {
    // fmt.Println("+", u)

    if len(u.next) == 0 {
        // fmt.Println("-", u)
        return
    }

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        Rec(v)

        u.delta += v.delta
        u.moves += v.moves

        lo = Min(lo, v.ActualValue())
        hi = Max(hi, v.ActualValue())
    }

    u.moves += hi - lo
    u.delta -= hi + lo

    // fmt.Println("-", u)
}

func Calc2(u *Node) (int64, int64) {
    if len(u.next) == 0 {
        return 0, 0
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        d, s := Calc2(v)

        delta += d
        sum += s

        lo = Min(lo, v.val)
        hi = Max(hi, v.val)
    }

    // fmt.Println(u.val, delta)

    u.val += delta
    return delta - u.val, sum + hi - lo
}

func Calc(u *Node) (int64, int64, int64) {
    if len(u.next) == 0 {
        fmt.Println("DONE", u.val)
        return u.val, -u.val, Abs(u.val)
    }

    var delta, sum int64

    lo := int64(math.MaxInt64)
    hi := int64(math.MinInt64)

    for v := range u.next {
        v, d, s := Calc(v)

        delta += d
        sum += s

        lo = Min(lo, v)
        hi = Max(hi, v)
    }

    fmt.Println("HERE", u.val, u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo)
    return u.val + delta - lo - hi, -u.val, sum + Abs(delta + u.val) + hi - lo

    // fmt.Println(u.val, sum, lo, hi)
    // return hi - lo

//     nv := u.val + delta

//     delta -= nv
//     sum += Abs(nv)

//     return delta, sum
}

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

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

func Max(args ...int64) int64 {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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


Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.Help Polycarpus and find any suitable method to cut the public key.

The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 108).

In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them. If there is no answer, print in a single line "NO" (without the quotes).

package main

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

var (
	s   string
	a   int
	b   int
	pow int
)

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

func main() {

	defer out.Flush()
	//in.Split(bufio.ScanWords)

	fmt.Fscan(in, &s)
	fmt.Fscan(in, &a, &b)

	n := len(s)
	ansA := make([]int, n)
	ansB := make([]int, n)
	num := make([]int, n)

	ansA[0], _ = strconv.Atoi(string(s[0]))
	ansB[n-1], _ = strconv.Atoi(string(s[n-1]))

	ansA[0] %= a
	ansB[n-1] %= b
	pow = 1 % b

	for i := 0; i < n; i++ {
		num[i] = int(s[i] - '0')
	}

	/*
		for i, j := 1, n-2; i < n; i, j = i+1, j-1 {

			ansA[i] = (ansA[i-1]*10 + num[i]) % a

			pow = pow * 10 % b

			ansB[j] = (pow*num[j] + ansB[j+1]) % b
		}
	*/

	for i := 1; i < n; i++ {
		ansA[i] = (ansA[i-1]*10 + num[i]) % a
	}

	for i := n - 2; i >= 0; i-- {
		pow = pow * 10 % b
		ansB[i] = (pow*num[i] + ansB[i+1]) % b
	}

	for i := 1; i < n; i++ {
		if num[i] > 0 && ansA[i-1] == 0 && ansB[i] == 0 {
			writeln("YES")
			writeln(s[:i])
			writeln(s[i:])
			return
		}
	}

	writeln("NO")

}

/*
func readStr(str *string) {
	//	*str, _ = in.ReadString()
	//*str = in.Text()
}

func readInt(num ...*int) {
	for _, value := range num {
		//in.Scan()
		b1 := make([]byte, 5)
		*value, _ = in.Read(b1)
		//*value, _ = strconv.Atoi(in.Text())
	}
}
*/
func writeln(str string) {
	out.WriteString(str + "\n")
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		modsOfB[i] = (digits[i]*m + modsOfB[i+1]) % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

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

	var s string
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}

	j := n - 2
	pow10 := 1
	r := int(s[n-1]-'0') % b
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

var rdr = bufio.NewReader(os.Stdin)
var rbuf = make([]byte, 0, 1<<21)

func readLine() string {
	rbuf = rbuf[:0]
	for {
		l, p, e := rdr.ReadLine()
		if e != nil && e != io.EOF {
			panic(e)
		}
		rbuf = append(rbuf, l...)
		if !p {
			return string(rbuf)
		}
	}
}

func main() {
	s0 := readLine()
	n := len(s0)
	s1 := readLine()
	var ab [2]int64
	for i, s := range strings.Split(s1, " ") {
		x, e := strconv.ParseInt(s, 10, 64)
		if e != nil {
			panic(e)
		}
		ab[i] = x
	}
	a, b := ab[0], ab[1]
	var d, ma, mb [1 << 21]int64
	for i, r := range s0 {
		d[i] = int64(r - '0')
	}
	for x, i := int64(0), 0; i < n-1; i++ {
		x = (x*10 + d[i]) % a
		ma[i] = x
	}
	for y, base, i := int64(0), int64(1), n-1; i > 0; i-- {
		y = (y + base*d[i]) % b
		base = base * 10 % b
		mb[i-1] = y
	}

	for i := 0; i < n-1; i++ {
		if ma[i] == 0 && mb[i] == 0 && d[i+1] > 0 {
			fmt.Println("YES")
			fmt.Println(s0[0 : i+1])
			fmt.Println(s0[i+1:])
			return
		}
	}
	fmt.Println("NO")
}

package main

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

var rdr = bufio.NewReader(os.Stdin)
var rbuf = make([]byte, 0, 1<<21)

func readLine() string {
	rbuf = rbuf[:0]
	for {
		l, p, e := rdr.ReadLine()
		if e != nil && e != io.EOF {
			panic(e)
		}
		rbuf = append(rbuf, l...)
		if !p {
			return string(rbuf)
		}
	}
}

func main() {
	s0 := readLine()
	n := len(s0)
	s1 := readLine()
	var ab [2]int64
	for i, s := range strings.Split(s1, " ") {
		x, e := strconv.ParseInt(s, 10, 64)
		if e != nil {
			panic(e)
		}
		ab[i] = x
	}
	a, b := ab[0], ab[1]
	var d, ma, mb [1 << 21]int64
	rs := make([]rune, n)
	for i, r := range s0 {
		rs[i] = r
		d[i] = int64(r - '0')
	}
	for x, i := int64(0), 0; i < n-1; i++ {
		x = (x*10 + d[i]) % a
		ma[i] = x
	}
	for y, base, i := int64(0), int64(1), n-1; i > 0; i-- {
		y = (y + base*d[i]) % b
		base = base * 10 % b
		mb[i-1] = y
	}

	for i := 0; i < n-1; i++ {
		if ma[i] == 0 && mb[i] == 0 && d[i+1] > 0 {
			fmt.Println("YES")
			fmt.Println(string(rs[0 : i+1]))
			fmt.Println(string(rs[i+1:]))
			return
		}
	}
	fmt.Println("NO")
}

package main

import (
	"fmt"
	"math/big"
	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)

	num1 := big.NewInt(0)
	num2 := big.NewInt(0)

	ans1 := big.NewInt(0)
	ans2 := big.NewInt(0)

	intA := big.NewInt(a)
	intB := big.NewInt(b)

	zero := big.NewInt(0)

	os.Exit(0)
	for i := 1; i < len(s); i++ {
		if s[i] != '0' {
			num1.SetString(s[:i], 10)
			num2.SetString(s[i:], 10)

			ans1 = big.NewInt(0).Mod(num1, intA)
			ans2 = big.NewInt(0).Mod(num2, intB)
			/*
				fmt.Printf("%s %s\n", num1, num2)
				fmt.Printf("%s %s\n", intA, intB)
				fmt.Printf("%s %s\n", ans1, ans2)
				fmt.Println("-----------------------")
			*/
			if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
				fmt.Println("YES")
				fmt.Printf("%s\n%s", num1, num2)

				os.Exit(0)
			}
		}
	}

	fmt.Println("NO")

}

package main

import (
	"fmt"
	"math/big"
	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)

	num1 := big.NewInt(0)
	num2 := big.NewInt(0)

	ans1 := big.NewInt(0)
	ans2 := big.NewInt(0)

	intA := big.NewInt(a)
	intB := big.NewInt(b)

	zero := big.NewInt(0)

	for i := 1; i < len(s); i++ {
		if s[i] != '0' {
			num1.SetString(s[:i], 10)
			num2.SetString(s[i:], 10)
			os.Exit(0)
			ans1 = big.NewInt(0).Mod(num1, intA)
			ans2 = big.NewInt(0).Mod(num2, intB)
			/*
				fmt.Printf("%s %s\n", num1, num2)
				fmt.Printf("%s %s\n", intA, intB)
				fmt.Printf("%s %s\n", ans1, ans2)
				fmt.Println("-----------------------")
			*/
			if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
				fmt.Println("YES")
				fmt.Printf("%s\n%s", num1, num2)

				os.Exit(0)
			}
		}
	}

	fmt.Println("NO")

}

package main

import (
	"fmt"
	//	"os"
	"strconv"
)

var (
	s   string
	a   int
	b   int
	num int
	pow int
	pp  bool
)

func main() {

	fmt.Scan(&s)
	fmt.Scan(&a, &b)

	n := len(s)
	ansA := make([]int, n)
	ansB := make([]int, n)

	ansA[0], _ = strconv.Atoi(string(s[0]))
	ansB[n-1], _ = strconv.Atoi(string(s[n-1]))

	ansA[0] %= a
	ansB[0] %= b
	pow = 1 % b

	for i, j := 1, n-2; i < n; i, j = i+1, j-1 {
		num, _ = strconv.Atoi(string(s[i]))
		num %= a
		ansA[i] = (ansA[i-1]*10 + num) % a

		pow = pow * 10 % b

		num, _ = strconv.Atoi(string(s[j]))
		num %= b
		ansB[j] = ((pow*num)%b + ansB[j+1]) % b
	}

	for i := 1; i < n-1; i++ {
		if s[i] != '0' && ansA[i-1] == 0 && ansB[i] == 0 {
			fmt.Print("YES\n")
			fmt.Printf("%s\n%s", s[:i], s[i:])
			pp = true
			break
		}
	}

	if !pp {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
	//	"math/big"
	//	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)
	/*
		num1 := big.NewInt(0)
		num2 := big.NewInt(0)

		ans1 := big.NewInt(0)
		ans2 := big.NewInt(0)

		intA := big.NewInt(a)
		intB := big.NewInt(b)

		zero := big.NewInt(0)
		//one := big.NewInt(1)

			for i := 1; i < len(s); i++ {
				if s[i] != '0' {
					num1.SetString(s[0:i], 10)
					num2.SetString(s[i:], 10)

					ans1 = big.NewInt(0).Mod(num1, intA)
					ans2 = big.NewInt(0).Mod(num2, intB)
					/*
						fmt.Printf("%s %s\n", num1, num2)
						fmt.Printf("%s %s\n", intA, intB)
						fmt.Printf("%s %s\n", ans1, ans2)
						fmt.Println("-----------------------")
					*
					if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
						fmt.Println("YES")
						fmt.Printf("%s\n%s", num1, num2)

						os.Exit(0)
					}
				}
			}
	*/
	fmt.Println("NO")

}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		fmt.Println(modsOfA[i], modsOfB[i+1], publicKey[i+1])
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 1; i < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 1; i < keyLength-1; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i < keyLength-1; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
		if modsOfA[i-1] == 0 && modsOfB[i] == 0 && d != 0 {
			res = YES
			resInd = i
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = m * 10 % b
		modsOfB[i] = (digits[i]*m + modsOfB[i+1]) % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i+1 < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(modsOfA)
	fmt.Println(modsOfB)

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i+1 < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

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

	var s []byte
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0] - '0')
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l%a == 0 {
			validPos = append(validPos, i)
		}
		l = 10*l + int(s[i]-'0')
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}
	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

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

	var s []byte
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}
	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

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

	var s string
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}

	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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