It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26). In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower).

NoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	capacity := 8 * 1024 * 1024
	s.Buffer(make([]byte, capacity), capacity)
	s.Split(bufio.ScanWords)

	s.Scan()
	s.Text()

	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	s.Scan()
	d := s.Text()

	f := make([]int, 26)
	l := make([]int, 26)
	for i := range f {
		l[i] = -1
		f[i] = -1
	}
	for i, c := range d {
		l[c-65] = i
		if f[c-65] == -1 {
			f[c-65] = i
		}
	}
	t := make([]int, len(d))
	for i := 0; i < 26; i++ {
		if f[i] != -1 {
			t[f[i]]++
		}
		if l[i] != -1 && l[i]+1 < len(d) {
			t[l[i]+1]--
		}
	}
	var m, cur int
	for i := 0; i < len(d); i++ {
		cur = cur + t[i]
		if m < cur {
			m = cur
		}
	}
	if m > k {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

package main

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

func solve() {
	readInt()
	k := readInt()
	q := readString()
	openAt := make([]bool, 26)
	closedAt := make([]int, 26)
	for i := 0; i < len(closedAt); i++ {
		closedAt[i] = -1
		openAt[i] = false
	}
	for i := 0; i < len(q); i++ {
		closedAt[q[i]-'A'] = i
	}

	for i := 0; i < len(q); i++ {
		v := q[i] - 'A'
		if !openAt[v] {
			k--
			if k < 0 {
				fmt.Println("YES")
				return
			}
			openAt[v] = true
		}
		if closedAt[v] == i {
			k++
		}
	}

	fmt.Println("NO")
}

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

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

	open := make([]int, 26)
	close := make([]int, 26)

	FillArray(open, -1)
	FillArray(close, -1)

	for i := N - 1; i >= 0; i-- {
		d := S[i] - 'A'
		open[d] = i
	}
	for i, c := range S {
		d := c - 'A'
		close[d] = i
	}

	for i := 0; i < N; i++ {
		guards := 0
		for d := 0; d < 26; d++ {
			if open[d] <= i && i <= close[d] {
				guards++
			}
		}
		if guards > K {
			io.Println("YES")
			return
		}
	}
	io.Println("NO")
}

func FillArray(arr []int, val int) {
	for i := range arr {
		arr[i] = val
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	K := sc.NextInt()

	S := sc.Next()

	As := make([]int, 26)
	Ae := make([]int, 26)

	for i, _ := range As {
		As[i] = -1
		Ae[i] = -1
	}

	for i, _ := range S {

		s := S[i]

		if As[s-'A'] < 0 {
			As[s-'A'] = i
		}

		Ae[s-'A'] = i
	}

	imos := make([]int, N+1)

	for i, _ := range As {
		if As[i] >= 0 {
			imos[As[i]]++
			imos[Ae[i]+1]--
		}
	}

	a := 0
	for i, _ := range imos {
		a += imos[i]
		if a > K {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	s.Scan()
	s.Text()

	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	s.Scan()
	d := s.Text()

	f := make([]int, 26)
	l := make([]int, 26)
	for i := range f {
		l[i] = -1
		f[i] = -1
	}
	for i, c := range d {
		l[c-65] = i
		if f[c-65] == -1 {
			f[c-65] = i
		}
	}
	t := make([]int, len(d))
	for i := 0; i < 26; i++ {
		if f[i] != -1 {
			t[f[i]]++
		}
		if l[i] != -1 {
			t[l[i]]--
		}
	}
	var m, cur int
	for i := 0; i < len(d); i++ {
		cur = cur + t[i]
		if m < cur {
			m = cur
		}
	}
	if m > k {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	s.Scan()
	s.Text()

	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	s.Scan()
	d := s.Text()

	f := make([]int, 26)
	l := make([]int, 26)
	for i := range f {
		l[i] = -1
		f[i] = -1
	}
	for i, c := range d {
		l[c-65] = i
		if f[c-65] == -1 {
			f[c-65] = i
		}
	}
	t := make([]int, len(d))
	for i := 0; i < 26; i++ {
		if f[i] != -1 {
			t[f[i]]++
		}
		if l[i] != -1 && l[i]+1 < len(d) {
			t[l[i]+1]--
		}
	}
	var m, cur int
	for i := 0; i < len(d); i++ {
		cur = cur + t[i]
		if m < cur {
			m = cur
		}
	}
	if m > k {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}


Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?

The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.

NoteIn the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do .In the second sample test, Memory can do .In the third sample test, Memory can do: .

package main

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

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

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

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

    var a []int = []int{y, y, y}
    res := 0

    i := 0
    j := 1
    k := 2

    for (a[i] < x) || (a[j] < x) || (a[k] < x) {
        res++
        a[k] = a[i] + a[j] - 1
        if a[k] > x {
            a[k] = x
        }
        i, j, k = j, k, i
    }

    fmt.Fprintf(bufout, "%d\n", res)
}

// http://codeforces.com/contest/712/problem/C
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

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

	return b
}

func check(m [3]int, val int) bool {
	return m[0] >= val && m[1] >= val && m[2] >= val
}

func main() {
	var x, y int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &x, &y)
	if x == y {
		fmt.Println("0")
		return
	}

	tr := [3]int{y, y, y}

	idx := 0
	ans := 0

	for {
		if tr[idx] >= x {
			idx = (idx + 1) % 3
			continue
		}

		ans++
		tr[idx] = min(int(math.Abs(float64(tr[(idx + 1) % 3] + tr[(idx + 2) % 3]))) - 1, x)
		if tr[idx] >= x {
			if check(tr, x) {
				break
			}
		}

		idx = (idx + 1) % 3

	}

	fmt.Println(ans)
}

package main

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

import "strings"

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

	x, _ := strconv.ParseInt(s[0], 10, 64)
	y, _ := strconv.ParseInt(s[1], 10, 64)
	if y > x {
		t := x
		x = y
		y = t
	}
	t := []int64{y, y, y}
	sec := 0
	for t[2] != x {
		v := t[0] + t[1] - 1
		if v >= x {
			v = x
		}
		t[2] = t[1]
		t[1] = t[0]
		t[0] = v
		sec += 1
	}
	fmt.Println(sec)
}


Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base p and regard the expression as written in the base p positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78 + 87 in the base 16 positional notation is equal to FF16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78 + 87 = ? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.

The first letter contains two space-separated numbers a and b (1 ≤ a, b ≤ 1000) which represent the given summands.

Print a single number — the length of the longest answer.

package main

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

func base1(n, b int) int {
    ans := 0
    for n > 0 {
        n = n/b
        ans += 1
    }
    return ans
}

func base(s string, b int) int {
    ans := 0
    k := len(s) - 1
    for i := 0; i < len(s); i++ {
        ans += (int(s[i])-48) * int(math.Pow(float64(b), float64(k)))
        k -= 1
    }
    return ans
}

func main(){
    var a, b int
    fmt.Scan(&a)
    fmt.Scan(&b)
    x := strconv.Itoa(a) + strconv.Itoa(b)
    z := uint8(48)
    for i := 0; i < len(x); i++ {
        if z < x[i] {
            z = x[i]
        }
    }
    d := int(z - 47)
    sum := base(strconv.Itoa(a), d) + base(strconv.Itoa(b), d)
    fmt.Print(base1(sum, d))

}

package main

import (
    "fmt"
    "strconv"
)

func base(s, b int) int {
    ans := 0
    for s > 0 {
        s = s/b
        ans += 1
    }
    return ans
}

func main(){
    var a, b int
    fmt.Scan(&a)
    fmt.Scan(&b)
    sum := a+b
    x := strconv.Itoa(a) + strconv.Itoa(b)
    z := uint8(48)
    for i := 0; i < len(x); i++ {
        if z < x[i] {
            z = x[i]
        }
    }
    fmt.Print(base(sum, int(z-47)))

}


Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.In order to pass through a guardpost, one needs to bribe both guards.The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!

The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.

In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.  The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them.

NoteExplanation of the first example.The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.Explanation of the second example.Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.

package main
import (
	"fmt"
)
func main() {
	var n,a,b,c,d,m1,m2,tot int
	fmt.Scan(&n)
	flag:=false
	for i:=0;i<4;i++ {
		fmt.Scan(&a,&b,&c,&d)
		if a>b {
			m1=b
		} else { m1=a }
		if c>d {
			m2=d
		} else { m2=c }
		tot=m1+m2
		if tot<=n {
			fmt.Println(i+1,m1,n-m1)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println("-1")
	}
}

package main

import "fmt"

func main() {
    var n,a,b,c,d,x,y,z int
    fmt.Scan(&n)
    for i := 0; i < 4; i++ {
        fmt.Scan(&a,&b,&c,&d)
        if (a+c) <= n {
            x = i+1; y = a; z = n-a;
        } else if (a+d) <= n {
            x = i+1; y = a; z = n-a;
        } else if (b+c) <= n {
            x = i+1; y = b; z = n-b;
        } else if (b+d) <= n {
            x = i+1; y = b; z = n-b;
        }
    }
    if (x == 0) { fmt.Println(-1) } else { fmt.Println(x,y,z) }
}

// 366A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, m1, m2 int
    var s [5][5]int
    fmt.Scan(&n)
    for i := 1; i <= 4; i++ {
        for j := 1; j <= 4; j++ {
            fmt.Scan(&s[i][j])
        }

    }
    for i := 1; i <= 4; i++ {
        m1 = int(math.Min(float64(s[i][1]), float64(s[i][2])))
        m2 = int(math.Min(float64(s[i][3]), float64(s[i][4])))
        if m1+m2 <= n {
            fmt.Println(i, m1, n-m1)
            return
        }
    }
    fmt.Println(-1)
}

package main
import (
	"fmt"
)
func main() {
	var n,a,b,c,d,m1,m2,tot int
	fmt.Scan(&n)
	flag:=false
	for i:=0;i<4;i++ {
		fmt.Scan(&a,&b,&c,&d)
		if a>b {
			m1=b
		} else { m1=a }
		if c>d {
			m1=d
		} else { m2=c }
		tot=m1+m2
		if tot<=n {
			fmt.Println(i+1,m1,n-m1)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println("-1")
	}
}

package main
import (
	"fmt"
)
func main() {
	var n,a,b,c,d,m1,m2,tot int
	fmt.Scan(&n)
	flag:=false
	for i:=0;i<4;i++ {
		fmt.Scan(&a,&b,&c,&d)
		if a>b {
			m1=b
		} else { m1=a }
		if c>d {
			m1=d
		} else { m2=c }
		tot=m1+m2
		if tot<=n {
			fmt.Println(i+1,m1,n-m1)
			flag=true
		}
	}
	if flag==false {
		fmt.Println("-1")
	}
}


The final match of the Berland Football Cup has been held recently. The referee has shown $$$n$$$ yellow cards throughout the match. At the beginning of the match there were $$$a_1$$$ players in the first team and $$$a_2$$$ players in the second team.The rules of sending players off the game are a bit different in Berland football. If a player from the first team receives $$$k_1$$$ yellow cards throughout the match, he can no longer participate in the match — he's sent off. And if a player from the second team receives $$$k_2$$$ yellow cards, he's sent off. After a player leaves the match, he can no longer receive any yellow cards. Each of $$$n$$$ yellow cards was shown to exactly one player. Even if all players from one team (or even from both teams) leave the match, the game still continues.The referee has lost his records on who has received each yellow card. Help him to determine the minimum and the maximum number of players that could have been thrown out of the game.

The first line contains one integer $$$a_1$$$ $$$(1 \le a_1 \le 1\,000)$$$ — the number of players in the first team. The second line contains one integer $$$a_2$$$ $$$(1 \le a_2 \le 1\,000)$$$ — the number of players in the second team. The third line contains one integer $$$k_1$$$ $$$(1 \le k_1 \le 1\,000)$$$ — the maximum number of yellow cards a player from the first team can receive (after receiving that many yellow cards, he leaves the game). The fourth line contains one integer $$$k_2$$$ $$$(1 \le k_2 \le 1\,000)$$$ — the maximum number of yellow cards a player from the second team can receive (after receiving that many yellow cards, he leaves the game). The fifth line contains one integer $$$n$$$ $$$(1 \le n \le a_1 \cdot k_1 + a_2 \cdot k_2)$$$ — the number of yellow cards that have been shown during the match.

Print two integers — the minimum and the maximum number of players that could have been thrown out of the game.

NoteIn the first example it could be possible that no player left the game, so the first number in the output is $$$0$$$. The maximum possible number of players that could have been forced to leave the game is $$$4$$$ — one player from the first team, and three players from the second.In the second example the maximum possible number of yellow cards has been shown $$$(3 \cdot 6 + 1 \cdot 7 = 25)$$$, so in any case all players were sent off.

package main

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

func scanner() string {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func main() {
	var input []string
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		input = append(input, scanner.Text())
	}
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())

	a1, _ := strconv.Atoi(input[0])
	a2, _ := strconv.Atoi(input[1])
	k1, _ := strconv.Atoi(input[2])
	k2, _ := strconv.Atoi(input[3])
	n, _ := strconv.Atoi(input[4])

	if k1 > k2 {
		k1, k2, a1, a2 = k2, k1, a2, a1
	}
	var min, max int

	if a1*k1 >= n {
		max = n / k1
	} else {
		max = a1
		max += (n - a1*k1) / k2
	}

	var minCard int

	if k1 > 1 {
		minCard = a1 * (k1 - 1)
	}
	if k2 > 1 {
		minCard += a2 * (k2 - 1)
	}

	if minCard >= n {
		min = 0
	} else {
		min = n - minCard
	}

	fmt.Printf("%v %v", min, max)
}

package main

import (
	"fmt"
)

func main() {
	var a1, a2, k1, k2, n int

	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&a1)
	fmt.Scanln(&a2)
	fmt.Scanln(&k1)
	fmt.Scanln(&k2)
	fmt.Scanln(&n)

	min := n - (((k1 - 1) * a1) + ((k2 - 1) * a2))

	if min <= 0 {
		min = 0
	} else if min >= a1+a2 {
		min = a1 + a2
	}

	max := 0
	if k1 < k2 {
		max = n / k1

		if max > a1 {
			max = a1
		} else if max < 1 {
			max = 0
		}
		n -= k1 * max

		x := n / k2
		if x > a2 {
			x = a2
		} else if x < 1 {
			x = 0
		}
		max += x

	} else {
		max = n / k2

		if max > a2 {
			max = a2
		} else if max < 1 {
			max = 0
		}
		n -= k2 * max

		x := n / k1
		if x > a1 {
			x = a1
		} else if x < 1 {
			x = 0
		}
		max += x
	}

	fmt.Println(min, max)

}

package main

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

var scan *bufio.Scanner
var writer io.Writer

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

func main() {
	solve()
}

func solve() {
	a1 := nextInt()
	a2 := nextInt()
	k1 := nextInt()
	k2 := nextInt()
	n := nextInt()

	//	a := a1+a2

	res1 := a1 + a2
	res2 := 0

	for i := 0; i <= a1; i++ {
		tmp1 := n - k1*i
		co1 := (k1 - 1) * (a1 - i)
		for j := 0; j <= a2; j++ {
			tmp2 := tmp1 - k2*j
			co2 := (k2 - 1) * (a2 - j)
			if tmp2 >= 0 {
				if tmp2 <= co1+co2 {
					sum := i + j
					if res1 > sum {
						res1 = sum
					}
					if res2 < sum {
						res2 = sum
					}
				}
			}
		}
	}

	fmt.Fprint(writer, res1, " ", res2)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

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

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func minPlayer(a1, a2, k1, k2, n int) int {
	n -= (k1-1)*a1 + (k2-1)*a2
	if n <= 0 {
		return 0
	}
	return min(a1+a2, n)
}

func maxPlayer(a1, a2, k1, k2, n int) int {
	p1 := min(a1, n/k1)
	n -= p1 * k1
	p2 := min(a2, n/k2)
	return p1 + p2
}

func main() {
	a1 := ReadInt()
	a2 := ReadInt()
	k1 := ReadInt()
	k2 := ReadInt()
	n := ReadInt()
	//ensure k1<k2
	if k1 > k2 {
		a1, a2 = a2, a1
		k1, k2 = k2, k1
	}
	fmt.Println(minPlayer(a1, a2, k1, k2, n), maxPlayer(a1, a2, k1, k2, n))
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

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

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

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

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

func readInt64() int64 {
	return readIntNbits(64)
}

func readInt() int {
	return int(readIntNbits(32))
}

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

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

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

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

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

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

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

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

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

	return string(res)
}

package main

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

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var a1, a2, k1, k2, n int

	fmt.Fscanf(reader, "%d\n", &a1)
	fmt.Fscanf(reader, "%d\n", &a2)
	fmt.Fscanf(reader, "%d\n", &k1)
	fmt.Fscanf(reader, "%d\n", &k2)
	fmt.Fscanf(reader, "%d\n", &n)

	if k1 < k2 {
		a1, a2 = a2, a1
		k1, k2 = k2, k1
	}

	r1 := n
	r1 -= a1 * (k1 - 1) + a2 * (k2 - 1)
	if r1 < 0 {
		r1 = 0
	}

	r2 := n
	r2 /= k2
	if r2 > a2 {
		r2 = a2
	}

	n -= r2 * k2

	r2 += n / k1

	fmt.Fprintf(writer, "%d %d\n", r1, r2)

	writer.Flush()
}

package main

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

func scanner() string {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func main() {
	var input []string
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		input = append(input, scanner.Text())
	}
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())
	// input = append(input, scanner())

	a1, _ := strconv.Atoi(input[0])
	a2, _ := strconv.Atoi(input[1])
	k1, _ := strconv.Atoi(input[2])
	k2, _ := strconv.Atoi(input[3])
	n, _ := strconv.Atoi(input[4])

	if a1*k1 > a2*k2 {
		k1, k2, a1, a2 = k2, k1, a2, a1
	}
	var min, max int

	if a1*k1 >= n {
		max = n / k1
	} else {
		max = a1
		max += (n - a1*k1) / k2
	}

	var minCard int

	if k1 > 1 {
		minCard = a1 * (k1 - 1)
	}
	if k2 > 1 {
		minCard += a2 * (k2 - 1)
	}

	if minCard >= n {
		min = 0
	} else {
		min = n - minCard
	}

	fmt.Printf("%v %v", min, max)
}

package main

import (
	"fmt"
)

func main() {
	var a1, a2, k1, k2, n int

	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&a1)
	fmt.Scanln(&a2)
	fmt.Scanln(&k1)
	fmt.Scanln(&k2)
	fmt.Scanln(&n)

	min := n - (((k1 - 1) * a1) + ((k2 - 1) * a2))

	if min <= 0 {
		min = 0
	} else if min >= a1+a2 {
		min = a1 + a2
	}

	max := 0
	if k1 < k2 {
		max = n / k1

		if max > a1 {
			max = a1
		} else if max < 1 {
			max = 0
		}
		n -= k1 * max

		x := n / k2
		if x > a2 {
			x = a2
		} else if x < 1 {
			x = 0
		}
		max += x

	} else {
		max = n / k2

		if max > a2 {
			max = a2
		} else if max < 1 {
			max = 0
		}
		n -= k2 * max

		x := n / k1
		if x > a1 {
			max = a1
		} else if x < 1 {
			max = 0
		}
		max += x
	}

	fmt.Println(min, max)

}

package main

import (
	"fmt"
)

func main() {
	var a1, a2, k1, k2, n int

	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&a1)
	fmt.Scanln(&a2)
	fmt.Scanln(&k1)
	fmt.Scanln(&k2)
	fmt.Scanln(&n)

	min := n - (((k1 - 1) * a1) + ((k2 - 1) * a2))

	if min <= 0 {
		min = 0
	} else if min >= a1+a2 {
		min = a1 + a2
	}

	max := 0
	if k1 < k2 {
		max = n / k1

		if max > a1+a2 {
			max = a1 + a2
		} else if max < 1 {
			max = 0
		}
		n -= k1 * max

		max += n / k2
		if max > a1+a2 {
			max = a1 + a2
		} else if max < 1 {
			max = 0
		}

	} else {
		max = n / k2

		if max > a2 {
			max = a2
		} else if max < 1 {
			max = 0
		}
		n -= k2 * max

		x := n / k1
		if x > a1 {
			max = a1
		} else if x < 1 {
			max = 0
		}
		max += x
	}

	fmt.Println(min, max)

}


There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of benches in the park. The second line contains a single integer $$$m$$$ $$$(1 \le m \le 10\,000)$$$ — the number of people additionally coming to the park. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \le a_i \le 100)$$$ — the initial number of people on the $$$i$$$-th bench.

Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.

NoteIn the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d\n%d\n", &n, &m)
	a := make([]int, 0, n)
	var ai int
	maxAi := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &ai)
		a = append(a, ai)
		if maxAi < ai {
			maxAi = ai
		}
	}
	complement := 0
	for _, ai = range a {
		complement += maxAi - ai
	}

	if m > complement {
		rest := m - complement
		avg := rest / n
		remainder := rest % n
		if remainder == 0 {
			fmt.Println(maxAi+avg, maxAi+m)
			return
		}
		fmt.Println(maxAi+avg+1, maxAi+m)
		return
	}
	fmt.Println(maxAi, maxAi+m)
}

package main

import "fmt"
import "math"

func main() {
	var n int
	var k int
	var a int

	fmt.Scanln(&n)
	fmt.Scanln(&k)

	mini := k
	maxi := 0
	for i := 0; i < n; i++ {
		fmt.Scanln(&a)
		mini = mini + a
		maxi = int(math.Max(float64(maxi), float64(a)))
	}

	mini = int(math.Max(math.Ceil(float64(mini) / float64(n)), float64(maxi)))
	maxi = maxi + k

	fmt.Println(mini, maxi)
}

package main

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

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

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

func ceilDiv(i, div int64) int64 {
    if div == 0 {
        return 0 // should not happen
    }
    if i % div == 0 {
        return i / div
    }
    return (i / div) + 1
}

func max(i, j int64) int64 {
    if i > j {
        return i
    }
    return j
}

func main() {
    defer writer.Flush()
    var n, m int64
    scanf("%d\n", &n)
    scanf("%d\n", &m)
    total := m
    maxSoFar := int64(0)
    for i := int64(0); i < n; i++ {
        var i int64
        scanf("%d\n", &i)
        total += i
        maxSoFar = max(maxSoFar, i)
    }
    minK := max(ceilDiv(total, n), maxSoFar)
    maxK := maxSoFar + m
    printf("%d %d", minK, maxK)
}

package main

import "fmt"
import "math"

func main() {
	var n int
	var k int
	var a int

	fmt.Scanln(&n)
	fmt.Scanln(&k)

	mini := k
	maxi := 0
	for i := 0; i < n; i++ {
		fmt.Scanln(&a)
		mini = mini + a
		maxi = int(math.Max(float64(maxi), float64(a)))
	}

	mini = int(math.Ceil(float64(mini) / float64(n)))
	maxi = maxi + k

	fmt.Println(mini, maxi)
}


During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.Cube is called solved if for each face of cube all squares on it has the same color.https://en.wikipedia.org/wiki/Rubik's_Cube

In first line given a sequence of 24 integers ai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.

Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.

NoteIn first test case cube looks like this:  In second test case cube looks like this:   It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.

package main

import (
	"fmt"
)

var rotate = [][]int{
	{5, 6, 17, 18, 21, 22, 13, 14},
	{7, 8, 19, 20, 23, 24, 15, 16},
	{3, 4, 19, 20, 23, 24, 15, 16},
	{1, 2, 18, 20, 12, 11, 15, 13},
	{2, 4, 6, 8, 10, 12, 23, 21},
	{1, 3, 5, 7, 9, 11, 24, 22}}

func main() {
	var cube = make([]int, 24)
	for i := 0; i < 24; i++ {
		fmt.Scanf("%d", &cube[i])
	}
	//rotate
	for i := 0; i < 6; i++ {
		//90-angle
		if check_rotate(cube, rotate[i], move_left2(rotate[i])) {
			fmt.Println("YES")
			return
		}
		//another 90-angle
		if check_rotate(cube, rotate[i], move_right2(rotate[i])) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func move_left2(in []int) []int {
	ret := append(in[2:len(in)], in[0:2]...)
	return ret
}

func move_right2(in []int) []int {
	ret := append(in[len(in)-2:len(in)], in[0:len(in)-2]...)
	return ret
}

func check_rotate(cube, rotate, moved []int) bool {
	after := make([]int, len(cube))
	copy(after, cube)
	for i := 0; i < 8; i++ {
		after[moved[i]-1] = cube[rotate[i]-1]
	}
	return check_solved(after)
}

func check_solved(cube []int) bool {
	for i := 0; i < 6; i++ {
		if cube[i*4] != cube[i*4+1] || cube[i*4] != cube[i*4+2] || cube[i*4] != cube[i*4+3] {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)

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

type Cube struct {
	elements [24]int
}

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

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

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

	return Turn{cube, wall}
}

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

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

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

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

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

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

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

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

	return perfect
}

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

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

	can := false

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

		if cube.IsPerfect() {
			can = true
		}

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

		if cube.IsPerfect() {
			can = true
		}

		cube.RotateLeft(turn)
	}

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

package main

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

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

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

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

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

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

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

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

import (
	"fmt"
)
var rotate = [][]int{
	{5,6,17,18,21,22,13,14},
	{7,8,19,20,23,24,15,16},
	{3,4,19,20,23,24,15,16},
	{1,2,18,20,12,11,15,13},
	{2,4,6,8,10,12,23,21},
	{1,3,5,7,9,11,24,22}}

func main() {
	var cube = make([]int,24)
	for i := 0; i<24 ; i++ {
		fmt.Scanf("%d", &cube[i])
	}
	//rotate
	for i:=0;i<6;i++{
		//90-angle
		if check_solved(cube,rotate[i],move_left2(rotate[i])) {
			fmt.Println("YES")
			return
		}
		//another 90-angle
		if check_solved(cube,rotate[i],move_right2(rotate[i])) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func move_left2(in []int) []int {
	ret:=make([]int,len(in))
	copy(ret,in[2:len(in)])
	copy(ret,in[0:2])
	return ret
}

func move_right2(in []int) []int {
	ret:=make([]int,len(in))
	copy(ret,in[len(in)-2:len(in)])
	copy(ret,in[0:len(in)-2])
	return ret
}

func check_solved(cube, rotate, moved []int) bool {
	after:=make([]int,len(cube))
	copy(after,cube)
	for i:=0;i<6;i++ {
		after[moved[i]-1]=cube[rotate[i]-1]
	}
	for i:=0;i<6;i++ {
		if after[i*4]== after[i*4+1] && after[i*4]== after[i*4+2] && after[i*4]== after[i*4+3] {
			return true
		}
	}
	return false
}

package main

import (
	"fmt"
)

var rotate = [][]int{
	{5, 6, 17, 18, 21, 22, 13, 14},
	{7, 8, 19, 20, 23, 24, 15, 16},
	{3, 4, 19, 20, 23, 24, 15, 16},
	{1, 2, 18, 20, 12, 11, 15, 13},
	{2, 4, 6, 8, 10, 12, 23, 21},
	{1, 3, 5, 7, 9, 11, 24, 22}}

func main() {
	var cube = make([]int, 24)
	for i := 0; i < 24; i++ {
		fmt.Scanf("%d", &cube[i])
	}
	//check already solved
	if check_solved(cube) {
		fmt.Println("YES")
		return
	}
	//rotate
	for i := 0; i < 6; i++ {
		//90-angle
		if check_rotate(cube, rotate[i], move_left2(rotate[i])) {
			fmt.Println("YES")
			return
		}
		//another 90-angle
		if check_rotate(cube, rotate[i], move_right2(rotate[i])) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func move_left2(in []int) []int {
	ret := make([]int, len(in))
	copy(ret, in[2:len(in)])
	copy(ret, in[0:2])
	return ret
}

func move_right2(in []int) []int {
	ret := make([]int, len(in))
	copy(ret, in[len(in)-2:len(in)])
	copy(ret, in[0:len(in)-2])
	return ret
}

func check_rotate(cube, rotate, moved []int) bool {
	after := make([]int, len(cube))
	copy(after, cube)
	for i := 0; i < 6; i++ {
		after[moved[i]-1] = cube[rotate[i]-1]
	}
	return check_solved(after)
}

func check_solved(cube []int) bool {
	for i := 0; i < 6; i++ {
		if cube[i*4] != cube[i*4+1] || cube[i*4] != cube[i*4+2] || cube[i*4] != cube[i*4+3] {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)

var rotate = [][]int{
	{5, 6, 17, 18, 21, 22, 13, 14},
	{7, 8, 19, 20, 23, 24, 15, 16},
	{3, 4, 19, 20, 23, 24, 15, 16},
	{1, 2, 18, 20, 12, 11, 15, 13},
	{2, 4, 6, 8, 10, 12, 23, 21},
	{1, 3, 5, 7, 9, 11, 24, 22}}

func main() {
	var cube = make([]int, 24)
	for i := 0; i < 24; i++ {
		fmt.Scanf("%d", &cube[i])
	}
	//check already solved
	if check_solved(cube) {
		fmt.Println("YES")
		return
	}
	//rotate
	for i := 0; i < 6; i++ {
		//90-angle
		if check_rotate(cube, rotate[i], move_left2(rotate[i])) {
			fmt.Println("YES")
			return
		}
		//another 90-angle
		if check_rotate(cube, rotate[i], move_right2(rotate[i])) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func move_left2(in []int) []int {
	ret := append(in[2:len(in)], in[0:2]...)
	return ret
}

func move_right2(in []int) []int {
	ret := append(in[len(in)-2:len(in)], in[0:len(in)-2]...)
	return ret
}

func check_rotate(cube, rotate, moved []int) bool {
	after := make([]int, len(cube))
	copy(after, cube)
	for i := 0; i < 8; i++ {
		after[moved[i]-1] = cube[rotate[i]-1]
	}
	return check_solved(after)
}

func check_solved(cube []int) bool {
	for i := 0; i < 6; i++ {
		if cube[i*4] != cube[i*4+1] || cube[i*4] != cube[i*4+2] || cube[i*4] != cube[i*4+3] {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)
var rotate = [][]int{
	{5,6,17,18,21,22,13,14},
	{7,8,19,20,23,24,15,16},
	{3,4,19,20,23,24,15,16},
	{1,2,18,20,12,11,15,13},
	{2,4,6,8,10,12,23,21},
	{1,3,5,7,9,11,24,22}}

func main() {
	var cube = make([]int,24)
	for i := 0; i<24 ; i++ {
		fmt.Scanf("%d", &cube[i])
	}
	//check already solved
	if check_solved(cube) {
		fmt.Println("YES")
		return
	}
	//rotate
	for i:=0;i<6;i++{
		//90-angle
		if check_rotate(cube,rotate[i],move_left2(rotate[i])) {
			fmt.Println("YES")
			return
		}
		//another 90-angle
		if check_rotate(cube,rotate[i],move_right2(rotate[i])) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func move_left2(in []int) []int {
	ret:=make([]int,len(in))
	copy(ret,in[2:len(in)])
	copy(ret,in[0:2])
	return ret
}

func move_right2(in []int) []int {
	ret:=make([]int,len(in))
	copy(ret,in[len(in)-2:len(in)])
	copy(ret,in[0:len(in)-2])
	return ret
}

func check_rotate(cube, rotate, moved []int) bool {
	after:=make([]int,len(cube))
	copy(after,cube)
	for i:=0;i<6;i++ {
		after[moved[i]-1]=cube[rotate[i]-1]
	}
	return check_solved(after)
}

func check_solved(cube []int) bool {
	for i:=0;i<6;i++ {
		if cube[i*4]!= cube[i*4+1] || cube[i*4]!= cube[i*4+2] || cube[i*4]!= cube[i*4+3] {
			return false
		}
	}
	return true
}

package main

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

func solve() {
	var data [6][2][2]int
	for i := 0; i < 20; i++ {
		data[i/4][(i%4)/2][i%2] = readInt()
	}
	data[5][1][1] = readInt()
	data[5][1][0] = readInt()
	data[5][0][1] = readInt()
	data[5][0][0] = readInt()

	var sides []int
	if isSideFull(&data, 3) && isSideFull(&data, 4) {
		sides = []int{0, 1, 2, 5}
	} else if isSideFull(&data, 0) && isSideFull(&data, 2) {
		sides = []int{1, 4, 5, 3}
	} else if isSideFull(&data, 1) && isSideFull(&data, 5) {
		sides = []int{0, 4, 2, 3}
	} else {
		fmt.Println("NO")
		return
	}
	rotate0(&data, 1, sides)
	if isSolved(&data) {
		fmt.Println("YES")
		return
	}
	rotate0(&data, -1, sides)
	rotate0(&data, -1, sides)
	if isSolved(&data) {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func isSolved(data *[6][2][2]int) bool {
	for i := 0; i < 6; i++ {
		if !isSideFull(data, i) {
			return false
		}
	}
	return true
}

func rotate0(data *[6][2][2]int, dir int, sides []int) {
	var nums [4][2]int
	for i := 0; i < len(sides); i++ {
		side := sides[i]
		for j := 0; j < 2; j++ {
			nums[i][j] = data[side][j][0]
		}
	}
	for i := 0; i < len(sides); i++ {
		side := sides[(i+dir+4)%4]
		for j := 0; j < 2; j++ {
			data[side][j][0] = nums[i][j]
		}
	}
}

func isSideFull(data *[6][2][2]int, side int) bool {
	color := data[side][0][0]
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			if data[side][i][j] != color {
				return false
			}
		}
	}
	return true
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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


A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.You're given a number. Determine if it is a magic number or not.

The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.

Print "YES" if n is a magic number or print "NO" if it's not.

package main
import (
	"fmt"
)
func main() {
	var n,d int
	s :=0
	m :=true
	fmt.Scan(&n)
	for n!=0 {
		d = n%10
		n/=10
		if d==1 {
			s=0
		} else if d==4 && s<2  {
			s++
		} else {
			m=false
		}
	}
	if s!=0 {
		m=false
	}
	if m==true {
		fmt.Println("YES")
	} else {
	fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var num string
	fmt.Scan(&num)

	for _, v := range []string{"144", "14", "1"} {
		num = strings.Replace(num, v, " ", -1)
	}
	num = strings.Replace(num, " ", "", -1)

	if len(num) > 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

import "fmt"

func main() {
    var input string
    var prev uint8 = 0
    var count int = 1
    var ok bool = true
    fmt.Scan(&input)
    for i:=0; i<len(input); i++ {
        if input[0] == '4' {
            ok = false
            break
        }
        if input[i] != '1' && input[i] != '4' {
            ok = false
            break
        }
        if input[i] == prev {
            count++
        } else {
            count = 1
        }
        if input[i] == '4' && count >= 3 {
            ok = false
            break
        }
        prev = input[i]
    }
    if ok {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  s := getS()
  n := len(s)
  pos := 0
  for pos < n {
    if pos+3 <= n && s[pos:pos+3] == "144" {
      pos += 3
    } else if pos+2 <= n && s[pos:pos+2] == "14" {
      pos += 2
    } else if s[pos:pos+1] == "1" {
      pos++
    } else {
      writer.WriteString("NO\n")
      return
    }
  }
  writer.WriteString("YES\n")
}

package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)
    ans, in := true, 0
    for in < len(s) {
        if s[in] == '1' {
            in++
            if in < len(s) {
                if s[in] == '4' { in++ }
                if in < len(s) {
                    if s[in] == '4' { in++ }
                }
            }
        } else {
            ans = false
            break
        }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    scanner.Scan()
    a := scanner.Text()
    a = strings.Replace(a,"144"," ",-1)
    a = strings.Replace(a,"14"," ",-1)
    a = strings.Replace(a,"1"," ",-1)
    if (strings.Trim(a, " ") == "") {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

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

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

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

var debug = false

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

func solve1() {
	input := getLine()
	ok, _ := regexp.Match("^(14{0,2})*$", []byte(input))
	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

func solve2() {
	input := getLine()

	ok := true

	for i := 0; i < len(input) && ok; i++ {
		if input[i] != '1' && input[i] != '4' {
			ok = false
		}
	}

	if ok && input[0] != '1' {
		ok = false
	}

	for i := 3; i < len(input) && ok; i++ {
		if input[i] == '4' && input[i-1] != '1' && input[i-2] != '1' {
			ok = false
		}
	}

	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

func main() {
	defer writer.Flush()

	input := getLine()

	status := 0
	ok := true
	for i := 0; i < len(input) && ok; i++ {
		switch status {
		case 0: // must see 1
			if input[i] == '1' {
				status = 1
			} else {
				ok = false
			}
		case 1: // already see 1
			if input[i] != '1' {
				if input[i] != '4' {
					ok = false
				} else {
					status = 2
				}
			}
		case 2: // already see 14
			if input[i] == '1' {
				status = 1
			} else if input[i] != '4' {
				ok = false
			} else {
				status = 0
			}
		}
	}
	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}

func main() {
	defer writer.Flush()

	input := getLine()
	ok, _ := regexp.Match("^(14{0,2})*$", []byte(input))
	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

package main

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

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

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

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

var debug = false

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

func main() {
	defer writer.Flush()

	input := getLine()

	ok := true

	for i := 0; i < len(input) && ok; i++ {
		if input[i] != '1' && input[i] != '4' {
			ok = false
		}
	}

	if ok && input[0] != '1' {
		ok = false
	}

	for i := 3; i < len(input) && ok; i++ {
		if input[i] == '4' && input[i-1] != '1' && input[i-2] != '1' {
			ok = false
		}
	}

	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

package main

import (
    "fmt"
)

func main() {
    var s string
    fmt.Scanf("%s", &s)
    for i:=len(s)-1; i>=0; {
        if s[i] == '4' {
            if i>1  && s[i-1] == '4' && s[i-2] == '1' {
                i -= 3
            } else if i>0 && s[i-1] =='1' {
                i -= 2
            } else {
                fmt.Println("NO")
                return
            }
        } else if s[i] == '1' {
            i -= 1
        } else {
            fmt.Println("NO")
            return
        }
    }
    fmt.Println("YES")
}

package main

import "fmt"

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

	foursExpect := 0
	okay := true

	for i := 0; i < len(line); i++ {
		switch line[i] {
		case '1':
			foursExpect = 2
		case '4':
			foursExpect--
			if foursExpect < 0 {
				okay = false
			}
		default:
			okay = false
		}
	}

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

package main

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

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

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

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

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  sc.Scan()
  s := sc.Text()
  c := 0
  if s[0] != '1' {
    w.WriteString("NO\n")
    w.Flush()
    return
  }
  for i := 0; i < len(s); i++ {
    if s[i] == '1' {
      if c >= 3 {
        w.WriteString("NO\n")
        w.Flush()
        return
      } else {
        c = 0
      }
    } else if s[i] == '4' {
      c++
    } else {
      w.WriteString("NO\n")
      w.Flush()
      return
    }
  }
  if c >= 3 {
    w.WriteString("NO\n")
    w.Flush()
    return
  }
  w.WriteString("YES\n")
  w.Flush()
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for n > 0 {
		if n % 1000 == 144 {
			n /= 1000
		} else if n % 100 == 14 {
			n /= 100
		} else if n % 10 == 1 {
			n /= 10
		} else {
			break
		}
	}
	if n > 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

import "fmt"

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

	ans := "NO"

loop:
	for {
		switch {
		case i == 0:
			ans = "YES"
			break loop
		case i%10 == 1:
			i /= 10
		case i%100 == 14:
			i /= 100
		case i%1000 == 144:
			i /= 1000
		default:
			break loop
		}
	}

	fmt.Println(ans)
}

package main

import "fmt"
import "regexp"

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

	r := regexp.MustCompile("^(14{0,2})+$")

	ans := "NO"
	if r.MatchString(s) {
		ans = "YES"
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var num string
	fmt.Scan(&num)

	for _, v := range []string{"144", "14", "1"} {
		num = strings.Replace(num, v, "", -1)
	}

	if len(num) > 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    scanner.Scan()
    a := scanner.Text()
    a = strings.Replace(a,"144","",-1)
    a = strings.Replace(a,"14","",-1)
    a = strings.Replace(a,"1","",-1)
    if (a == "") {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

import "fmt"

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

	foursExpect := 2
	okay := true

	for i := 0; i < len(line); i++ {
		switch line[i] {
		case '1':
			foursExpect = 2
		case '4':
			foursExpect--
			if foursExpect < 0 {
				okay = false
			}
		default:
			okay = false
		}
	}

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

package main

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

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

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

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

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  sc.Scan()
  s := sc.Text()
  c := 0
  for i := 0; i < len(s); i++ {
    if s[i] == '1' {
      if c >= 3 {
        w.WriteString("NO\n")
        w.Flush()
        return
      } else {
        c = 0
      }
    } else if s[i] == '4' {
      c++
    } else {
      w.WriteString("NO\n")
      w.Flush()
      return
    }
  }
  if c >= 3 {
    w.WriteString("NO\n")
    w.Flush()
    return
  }
  w.WriteString("YES\n")
  w.Flush()
}