package main

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

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

const mod =  998244353
const N = 2
var n, m, L, R int

type matrix struct {
	f[N][N] int64
}

func print_out(a matrix)  {
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			fmt.Fprintf(writer, "%d ", a.f[i][j])
		}
		fmt.Fprintf(writer, "\n")
	}
}

func mul(a matrix, b matrix) matrix {
	var c = matrix{}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			for k := 0; k < N; k++ {
				c.f[i][j] += a.f[i][k] * b.f[k][j]
				c.f[i][j] %= mod
			}
		}
	}
	return c
}

func pw(a matrix, b int64) matrix {
	var ret = matrix{}
	for i := 0; i < N; i++ {
		ret.f[i][i] = 1
	}

	for b > 0 {
		if (b & 1) == 1 {
			ret = mul(ret, a)
			b--
		} else {
			a = mul(a, a)
			b /= 2
		}
	}
	return ret
}

func main()  {
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d %d %d", &n, &m, &L, &R)

	var O = int64(R - L + 1) / 2
	var E = int64(R - L + 1) / 2
	if (R - L + 1) % 2 != 0 {
		if L%2 == 0 {
			E++
		} else {
			O++
		}
	}

	var T = int64(n) * int64(m)

	var mt = matrix{}
	mt.f[0][0] = E
	mt.f[0][1] = O
	mt.f[1][0] = O
	mt.f[1][1] = E

	//print_out(mt)

	mt = pw(mt, T - 1)

	//print_out(mt)

	var dp_odd = O
	var dp_evn = E

	var fn_dp_odd = mt.f[0][0] * dp_odd % mod + mt.f[1][0] * dp_evn % mod
	fn_dp_odd %= mod

	var fn_dp_evn = mt.f[1][0] * dp_odd % mod + mt.f[1][1] * dp_evn % mod
	fn_dp_evn %= mod

	var ret int64
	if T % 2 == 1 {
		ret = (fn_dp_odd + fn_dp_evn) % mod
	} else {
		ret = fn_dp_evn
	}

	fmt.Fprintf(writer, "%d", ret)
}

package main

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

const mod =  998244353
var n, m, L, R int

func pw(a int64, b int64) int64 {
	if a == 0 {
		if b == 0 {
			return 1
		}
		return 0
	}
	var ret = int64(1)

	for b > 0 {
		if (b & 1) == 1 {
			ret = ret * a % mod
			b--
		} else {
			a = a * a % mod
			b /= 2
		}
	}
	return ret
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d %d %d", &n, &m, &L, &R)

	var diff = R - L + 1
	var odd = diff / 2
	var evn = diff / 2

	if diff % 2 != 0 {
		if L % 2 == 0 {
			evn++
		} else {
			odd++
		}
	}

	var T = int64(n) * int64(m)

	var ret = pw(int64(evn + odd), T)
	ret = (ret + pw(int64(evn - odd + mod), T)) % mod

	if ret < 0 {
		ret += mod
	}

	if T % 2 == 1 {
		evn, odd = odd, evn
		ret += pw(int64(evn + odd), T)
		ret %= mod
		ret += pw(int64(evn - odd + mod), T)
		ret %= mod
	}

	ret = ret * pw(2, mod - 2) % mod
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

const mod =  998244353
var n, m, L, R int

func pw(a int, b int) int {
	if a == 0 {
		if b == 0 {
			return 1
		}
		return 0
	}
	var ret = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret = int(int64(ret) * int64(a) % mod)
			b--
		} else {
			a = int(int64(a) * int64(a) % mod)
			b /= 2
		}
	}
	return ret
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d %d %d", &n, &m, &L, &R)

	var diff = R - L + 1
	var odd = diff / 2
	var evn = diff / 2

	if diff % 2 != 0 {
		if L % 2 == 0 {
			evn++
		} else {
			odd++
		}
	}

	var T = int(int64(n) * int64(m) % (mod - 1))
	var ret = pw(evn + odd, T)
	ret = (ret + pw(evn - odd + mod, T)) % mod

	if ret < 0 {
		ret += mod
	}

	if int64(n) * int64(m) % 2 == 1 {
		evn, odd = odd, evn
		ret += pw(evn + odd, T)
		ret %= mod
		ret += pw(evn - odd + mod, T)
		ret %= mod
	}

	ret = int(int64(ret) * int64(pw(2, mod - 2)) % mod)
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

const mod =  998244353
var n, m, L, R int

func pw(a int, b int) int {
	if a == 0 {
		if b == 0 {
			return 1
		}
		return 0
	}
	var ret = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret = int(int64(ret) * int64(a) % mod)
			b--
		} else {
			a = int(int64(a) * int64(a) % mod)
			b /= 2
		}
	}
	return ret
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d %d %d", &n, &m, &L, &R)

	var diff = R - L + 1
	var odd = diff / 2
	var evn = diff / 2

	if diff % 2 != 0 {
		if L % 2 == 0 {
			evn++
		} else {
			odd++
		}
	}

	var T = int(int64(n) * int64(m) % (mod - 1))
	var ret = pw(evn + odd, T)
	ret = (ret + pw(evn - odd, T)) % mod

	if ret < 0 {
		ret += mod
	}

	ret = int(int64(ret) * int64(pw(2, mod - 2)) % mod)
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

const mod =  998244353
var n, m, L, R int

func pw(a int, b int) int {
	if a == 0 {
		if b == 0 {
			return 1
		}
		return 0
	}
	var ret = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret = int(int64(ret) * int64(a) % mod)
			b--
		} else {
			a = int(int64(a) * int64(a) % mod)
			b /= 2
		}
	}
	return ret
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d %d %d", &n, &m, &L, &R)

	var diff = R - L + 1
	var odd = diff / 2
	var evn = diff / 2

	if diff % 2 != 0 {
		if L % 2 == 0 {
			evn++
		} else {
			odd++
		}
	}

	var T = int(int64(n) * int64(m) % (mod - 1))
	var ret = pw(evn + odd, T)
	ret = (ret + pw(evn - odd, T)) % mod

	if ret < 0 {
		ret += mod
	}

       // review
	ret = int(int64(ret) * int64(pw(2, mod - 2)) % mod)
	fmt.Fprintf(writer, "%d", ret)
}


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


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

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


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)

}


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


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


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


package main

import (
	"math"
	"fmt"
)

const maxN = 4000

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

	return a
}

func resolver(a, b, c, n int) int {
	if n > maxN {
		panic("Limit exceeded")
	}

	memo := make([]int, maxN + 1)
	units := make([]int, 3)

	units[0], units[1], units[2] = a, b, c
	memo[0] = 0
	memo[a] = 1
	memo[b] = 1
	memo[c] = 1

	for i := 1; i <= n; i++ {
		var localMax int = math.MinInt32

		for _, v := range(units) {
			if delta := i - v; delta >= 0 && delta <= n {
				var localMaxCand int = intMax(localMax, memo[delta] + 1)

				if localMaxCand > localMax {
					localMax = localMaxCand
					memo[i] = localMax
				}
			}
		}

		memo[i] = localMax
	}

	return memo[n]
}

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

	fmt.Println(resolver(a, b, c, n))
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	line, _ := Readln(reader)
	numbers := readIntArray(line)

	length := numbers[0]
	lengths := numbers[1:]

	cache := make(map[int]int, 0)
	sort.Ints(lengths)
	fmt.Println(Cut(length, lengths, 0, cache))
}

func Cut(length int, lengths []int, pieces int, cache map[int]int) int {

	if cached, ok := cache[length]; ok {
		return cached
	}

	maxPieces := pieces
	isCut := false
	for _, ln := range lengths {
		if (length - ln) >= 0 {
			newPieces := Cut(length - ln, lengths, pieces + 1, cache)
			if maxPieces < newPieces {
				isCut = true
				maxPieces = newPieces
			}
		}
	}

	if (!isCut) && length > 0 {
		maxPieces = -1
		cache[length] = maxPieces
	} else if isCut {
		cache[length] = maxPieces
	}

	return maxPieces
}

package main

import "fmt"

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

func main() {

    var n int

    var a [3]int

    fmt.Scan(&n,&a[0],&a[1],&a[2])

    dp := make([]int,n+1)

    dp[0] = 0

    for i := 1; i <= n; i++ {

        dp[i] = -999999999

        for k := 0; k < 3; k++ {

            if (i-a[k]) >= 0 {

                dp[i] = max(dp[i],1+dp[i-a[k]])

            }

        }

    }

    fmt.Println(dp[n])

}

package main

import "fmt"

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

func main() {
	var n int
	var a [3]int
	fmt.Scan(&n, &a[0], &a[1], &a[2])
	dp := make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = -999999999
		for k := 0; k < 3; k++ {
			if (i - a[k]) >= 0 {
				dp[i] = max(dp[i], 1+dp[i-a[k]])
			}
		}
	}
	fmt.Println(dp[n])
}

package main

import "fmt"

const maxn = 4000 + 10

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

func main() {
	var n, a, b, c int
	var dp [maxn]int
	fmt.Scan(&n, &a, &b, &c)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = -0x3f3f3f3f
	}
	for i := 1; i <= n; i++ {
		if i >= a {
			dp[i] = max(dp[i], dp[i-a]+1)
		}
		if i >= b {
			dp[i] = max(dp[i], dp[i-b]+1)
		}
		if i >= c {
			dp[i] = max(dp[i], dp[i-c]+1)
		}
	}
	if dp[n] < 0 {
		dp[n] = 0
	}
	fmt.Printf("%d\n", dp[n])
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/189/A
// комментарии к решению
// Задача решается полным перебором. Для сокращения кол-ва операций
// итерируемся с максимального возможного вниз, т.к. в цикле for
// вычисления из init производяться один раз (сокращается кол-во операций)
func taskSolution(n, a, b, c int) int {
	max := 0
	for i := n / a; i >= 0; i -= 1 {
		for j := (n - i*a) / b; j >= 0; j -= 1 {
			left := n - i*a - j*b
			if left%c == 0 && max < i+j+left/c {
				max = i + j + left/c
			}
		}
	}
	return max
}

func main() {
	var n, a, b, c int
	if _, err := fmt.Scan(&n, &a, &b, &c); err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(n, a, b, c))
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

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

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

  dp := make([]int, n+1)

  for i, _ := range dp {
    dp[i] = -1
  }
  dp[0] = 0

  for i:=1; i <= n; i++ {
    for _, j := range []int{a, b, c} {
      if i-j >= 0 && dp[i-j] != -1 {
        dp[i] = max(dp[i], dp[i-j]+1)
      }
    }
  }
  printf("%d\n", dp[n])
}

package main

import (
	"fmt"
)

func main() {
	var n,a,b,c int
	s:=0
	fmt.Scan(&n,&a,&b,&c)
	for i:=0;i<=n/a;i++ {
		z:=n-i*a
		for k:=0; k<=z/b;k++ {
			h:=i+k+(z-k*b)/c
			if (z-k*b)%c==0 && h>s {
				s=h
			}
		}
	}
	fmt.Println(s)
}

package main

import "fmt"
import "sort"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	//maxP := bruteForce(n, a, b, c)
	maxP := dp(n, a, b, c)
	fmt.Print(maxP)
}

func dp(n, a, b, c int) int {
	dp := make([]int, 4001)
	dp[a] = 1
	dp[b] = 1
	dp[c] = 1
	for i := 1; i <= n; i++ {
		dp[i] = max(dp, i, i-a, i-b, i-c)
	}
	return dp[n]
}

func max(dp []int, nrs ...int) int {
	m := dp[nrs[0]]
	for _, nr := range nrs[1:] {
		if nr < 0 || dp[nr] == 0 {
			continue
		}
		if dp[nr]+1 > m {
			m = dp[nr] + 1
		}
	}
	return m
}

func bruteForce(n, a, b, c int) int {
	var maxP int
	ls := []int{a, b, c}
	sort.Sort(sort.Reverse(sort.IntSlice(ls)))
	for i := 0; i <= n/ls[0]; i++ {
		for j := 0; j <= n/ls[1]; j++ {
			d := n - i*ls[0] - j*ls[1]
			if d%ls[2] == 0 {
				k := d / ls[2]
				if maxP < i+j+k {
					maxP = i + j + k
				}
			}
		}
	}
	return maxP
}

package main

import "fmt"
import "sort"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	var maxP int
	ls := []int{a, b, c}
	sort.Sort(sort.Reverse(sort.IntSlice(ls)))
	for i := 0; i <= n/ls[0]; i++ {
		for j := 0; j <= n/ls[1]; j++ {
			d := n - i*ls[0] - j*ls[1]
			if d%ls[2] == 0 {
				k := d / ls[2]
				if maxP < i+j+k {
					maxP = i + j + k
				}
			}
		}
	}
	fmt.Print(maxP)
}

// http://codeforces.com/problemset/problem/189/A
package main

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

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

const (
	MOD = 1e9 + 7
)

type (

)

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

	return b
}

func main () {
	var (
		n, a, b, c int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &a, &b, &c)

	dp := make([]struct{cnt, l int}, 1e4 + 1)

	dp[0].l = n
	dp[0].l = n
	dp[0].l = n

	for i := 0; i <= n; i++ {
		if dp[i].cnt + 1 > dp[i + a].cnt && dp[i].l - a >= 0 {
			dp[i + a].cnt = dp[i].cnt + 1
			dp[i + a].l = dp[i].l - a
		}

		if dp[i].cnt + 1 > dp[i + b].cnt && dp[i].l - b >= 0 {
			dp[i + b].cnt = dp[i].cnt + 1
			dp[i + b].l = dp[i].l - b
		}

		if dp[i].cnt + 1 > dp[i + c].cnt && dp[i].l - c >= 0 {
			dp[i + c].cnt = dp[i].cnt + 1
			dp[i + c].l = dp[i].l - c
		}
	}

	fmt.Println(max(max(dp[n].cnt, dp[n].cnt), dp[n].cnt))
}

package main

import (
	"fmt"
)

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

func main() {
	var n, a, b, c int
	t := []int{0}
	fmt.Scanf("%d %d %d %d \n", &n, &a, &b, &c)
	for i := 1; i <= n; i++ {
		t = append(t, -1)
		if i >= a && t[i-a] != -1 {
			t[i] = max(t[i], t[i-a]+1)
		}
		if i >= b && t[i-b] != -1 {
			t[i] = max(t[i], t[i-b]+1)
		}
		if i >= c && t[i-c] != -1 {
			t[i] = max(t[i], t[i-c]+1)
		}
	}
	fmt.Print(t[n])
}

package main

import "fmt"

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

func main() {
    var n int
    var a [3]int
    fmt.Scan(&n,&a[0],&a[1],&a[2])
    dp := make([]int,n+1)
    dp[0] = 0
    for i := 1; i <= n; i++ {
        dp[i] = -999999999
        for k := 0; k < 3; k++ {
            if (i-a[k]) >= 0 {
                dp[i] = max(dp[i],1+dp[i-a[k]])
            }
        }
    }
    fmt.Println(dp[n])
}

package main

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

var n, a, b, c int
var res []int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	raw := scanner.Text()
	segs := strings.Split(raw, " ")
	n, _ = strconv.Atoi(segs[0])
	a, _ = strconv.Atoi(segs[1])
	b, _ = strconv.Atoi(segs[2])
	c, _ = strconv.Atoi(segs[3])

	d := Do()
	fmt.Println(d)
}

func Do() int {
	res = make([]int, n+1, n+1)
	for idx := 1; idx <= n; idx++ {
		res[idx] = Cut(idx)
		// fmt.Println("res", idx, res)
	}
	return res[n]
}

func Cut(idx int) int {
	if idx == 0 {
		return 0
	}
	max := 0
	if idx >= a {
		left := idx - a
		if left == 0 {
			max = 1
			goto bnote
		} else {
			if res[left] == 0 {
				max = 0
				goto bnote
			} else {
				max = 1 + res[left]
			}
		}
	}
bnote:
	bmax := 0
	{
		if idx >= b {
			left := idx - b
			if left == 0 {
				bmax = 1
				goto cnote
			} else {
				if res[left] == 0 {
					bmax = 0
					goto cnote
				} else {
					bmax = 1 + res[left]
				}
			}
		}
	}
cnote:
	cmax := 0
	{
		if idx >= c {
			left := idx - c
			if left == 0 {
				cmax = 1
				goto over
			} else {
				if res[left] == 0 {
					cmax = 0
					goto over
				} else {
					cmax = 1 + res[left]
				}
			}
		}
	}
over:
	{
		zhi := max3(max, bmax, cmax)
		return zhi
	}
}

func max3(a, b, c int) int {
	res := []int{a, b, c}
	// fmt.Println(res)
	sort.Ints(res)
	return res[2]
}

package main

import "fmt"

var dp [8005]int

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

	dp[a], dp[b], dp[c] = 1, 1, 1
	for i := 1; i <= n; i++ {
		if dp[i] > 0 {
			dp[i+a] = max(dp[i+a], dp[i]+1)
			dp[i+b] = max(dp[i+b], dp[i]+1)
			dp[i+c] = max(dp[i+c], dp[i]+1)
		}
	}

	fmt.Println(dp[n])
}

func max(x, y int) int {
	if x < y {
		x = y
	}

	return x
}

package main

import "fmt"

func Max(a, b int) int {
    result := a
    if b > a {
        result = b
    }

    return result
}

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

    arr := []int{a, b, c}
    dp := make([]int, n + 1)
    dp[0] = 1

    for i := 1; i <= n; i++ {
        var max int = 0
        for _, v := range arr {
            var cur_i int = i - v
            if cur_i >= 0 && dp[cur_i] != 0 {
                max = Max(max, dp[cur_i] + 1)
            }
        }

        dp[i] = max
    }

    fmt.Println(dp[n] - 1)
}

package main

import "fmt"

var dp [4005]int

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}

	for i := 1; i < len(dp); i++ {
		dp[i] = -100000
	}
	for i := a; i <= n; i++ {
		dp[i] = max(dp[i], dp[i-a]+1)
		if i >= b {
			dp[i] = max(dp[i], dp[i-b]+1)
		}
		if i >= c {
			dp[i] = max(dp[i], dp[i-c]+1)
		}
	}

	fmt.Println(dp[n])
}

func max(x, y int) int {
	if x < y {
		x = y
	}

	return x
}

package main

import "fmt"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}

	n1 := n / a
	n2 := n / b
	n3 := n / c
	if n%a == 0 || (a == b && b == c) {
		fmt.Println(n1)
		return
	}

	max := 0
	if a == b || b == c {
		for i := 0; i <= n1; i++ {
			for j := 0; j <= n3; j++ {
				v := i*a + j*c
				if v >= n {
					if v == n && i+j > max {
						max = i + j
					}
					break
				}
			}
		}
		fmt.Println(max)
		return
	}

	for i := 0; i <= n1; i++ {
		for j := 0; j <= n2; j++ {
			for k := 0; k <= n3; k++ {
				v := i*a + j*b + k*c
				if v >= n {
					if v == n && i+j+k > max {
						max = i + j + k
					}
					break
				}
			}
		}
	}

	fmt.Println(max)
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var a [3]int

func main() {
	fmt.Fscan(reader, &n, &a[0], &a[1], &a[2])
	dp := make([]int, n+1)
	ok := make([]bool, n+1)
	ok[0] = true
	for i := 1; i <= n; i++ {
		for j := 0; j < 3; j++ {
			if i >= a[j] && dp[i] < dp[i-a[j]]+1 && ok[i-a[j]] {
				dp[i] = dp[i-a[j]] + 1
				ok[i] = true
			}
		}
	}
	fmt.Println(dp[n])
}

package main

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

var DEBUG = true

func main() {
	defer Flush()

	n := readi()
	a := readi()
	b := readi()
	c := readi()

	dp := make([]int, n+1)
	for i := range dp {
		dp[i] = -1
	}
	dp[0] = 0

	for i := 0; i <= n; i++ {
		if dp[i] < 0 {
			continue
		}
		for _, v := range []int{a, b, c} {
			j := i + v
			if n < j {
				continue
			}
			dp[j] = max(dp[j], dp[i]+1)
		}
	}
	println(dp[n])
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

var DEBUG = true

func main() {
	defer Flush()

	n := readi()
	a := readi()
	b := readi()
	c := readi()

	var ans int
	for i := 0; i*a <= n; i++ {
		for j := 0; j*b <= n-i*a; j++ {
			m := n - i*a - j*b
			if m%c == 0 {
				ans = max(ans, i+j+m/c)
			}
		}
	}
	println(ans)
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func MaxOf(vars ...int) int {
	max := vars[0]

	for _, i := range vars {
		if max < i {
			max = i
		}
	}

	return max
}

func main() {
	var reader io.Reader
	var writer io.Writer

	reader = os.Stdin
	writer = os.Stdout

	//file, _ := os.Open("input.txt")
	//reader = file

	var n, a, b, c int

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

	f := make([]int, n+a+b+c+1)
	f[a] = 1
	f[b] = 1
	f[c] = 1

	for i := 0; i <= n; i++ {
		if i >= a && f[i-a] != 0 {
			f[i] = MaxOf(f[i-a]+1, f[i])
		}
		if i >= b && f[i-b] != 0 {
			f[i] = MaxOf(f[i-b]+1, f[i])
		}
		if i >= c && f[i-c] != 0 {
			f[i] = MaxOf(f[i-c]+1, f[i])
		}
	}

	fmt.Fprintln(writer, f[n])

}

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)
  n, a, b, c := ni(), ni(), ni(), ni()
  max := 0
  for i := 0; i*a <= n; i++ {
    for j := 0; j*b <= n-i*a; j++ {
      n2 := n - i*a - j*b
      if n2%c == 0 && n2/c+i+j > max {
        max = n2/c + i + j
      }
    }
  }
  pri(max)
  w.Flush()
}

package main

import "fmt"
import "sort"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	//maxP := bruteForce(n, a, b, c)
	maxP := dp(n, a, b, c)
	fmt.Print(maxP)
}

func dp(n, a, b, c int) int {
	dp := make([]int, n+1)
	dp[a] = 1
	dp[b] = 1
	dp[c] = 1
	for i := 1; i <= n; i++ {
		if i-a > 0 && a != 0 {
			dp[i] = max(dp[i], dp[i-a]+1)
			continue
		}
		if i-b > 0 && b != 0 {
			dp[i] = max(dp[i], dp[i-b]+1)
			continue
		}
		if i-c > 0 && c != 0 {
			dp[i] = max(dp[i], dp[i-c]+1)
			continue
		}
	}
	return dp[n]
}

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

func bruteForce(n, a, b, c int) int {
	var maxP int
	ls := []int{a, b, c}
	sort.Sort(sort.Reverse(sort.IntSlice(ls)))
	for i := 0; i <= n/ls[0]; i++ {
		for j := 0; j <= n/ls[1]; j++ {
			d := n - i*ls[0] - j*ls[1]
			if d%ls[2] == 0 {
				k := d / ls[2]
				if maxP < i+j+k {
					maxP = i + j + k
				}
			}
		}
	}
	return maxP
}

package main

import (
	"math"
	"fmt"
)

const maxN = 4000

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

	return a
}

func resolver(a, b, c, n int) int {
	if n > maxN {
		panic("Limit exceeded")
	}

	memo := make([]int, n+1)
	units := make([]int, 3)

	units[0], units[1], units[2] = a, b, c
	memo[0] = 0
	memo[a] = 1
	memo[b] = 1
	memo[c] = 1

	for i := 1; i <= n; i++ {
		var localMax int = math.MinInt32

		for _, v := range(units) {
			if delta := i - v; delta >= 0 {
				var localMaxCand int = intMax(memo[i], memo[delta] + 1)

				if localMaxCand > localMax {
					localMax = localMaxCand
					memo[i] = localMax
				}
			}
		}

		memo[i] = localMax
	}

	return memo[n]
}

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

	fmt.Println(resolver(a, b, c, n))
}

package main

import "fmt"

var dp [4005]int

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}

	for i := 1; i < len(dp); i++ {
		dp[i] = -100000
	}
	for i := a; i <= n; i++ {
		dp[i] = dp[i-a] + 1
		if i > b {
			dp[i] = max(dp[i], dp[i-b]+1)
		}
		if i > c {
			dp[i] = max(dp[i], dp[i-c]+1)
		}
	}

	fmt.Println(dp[n])
}

func max(x, y int) int {
	if x < y {
		x = y
	}

	return x
}

package main

import "fmt"

var dp [4005]int

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}

	dp[a], dp[b], dp[c] = 1, 1, 1
	for i := a; i <= n; i++ {
		dp[i] = dp[i-a] + 1
		if i > b {
			dp[i] = max(dp[i], dp[i-b]+1)
		}
		if i > c {
			dp[i] = max(dp[i], dp[i-c]+1)
		}
	}

	fmt.Println(dp[n])
}

func max(x, y int) int {
	if x < y {
		x = y
	}

	return x
}

package main

import "fmt"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}

	n1 := n / a
	n2 := n / b
	n3 := n / c
	if n%a == 0 || (a == b && b == c) {
		fmt.Println(n1)
		return
	}

	max := 0
	if a == b || b == c {
		for i := 0; i < n1; i++ {
			for j := 0; j < n3; j++ {
				v := i*a + j*c
				if v >= n {
					if v == n && i+j > max {
						max = i + j
					}
					break
				}
			}
		}
		fmt.Println(max)
		return
	}

	for i := 0; i <= n1; i++ {
		for j := 0; j <= n2; j++ {
			for k := 0; k <= n3; k++ {
				v := i*a + j*b + k*c
				if v >= n {
					if v == n && i+j+k > max {
						max = i + j + k
					}
					break
				}
			}
		}
	}

	fmt.Println(max)
}

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 dioph(b, c, n int) (int, bool) {
  max := 0
  noerr := false
  for k := 0; k*b <= n; k++ {
    if (n-k*b)%c == 0 && k+(n-k*b)/c > max {
      max = k + (n-k*b)/c
      noerr = true
    }
  }
  return max, noerr
}

func main() {
  sc.Split(bufio.ScanWords)
  n, a, b, c := ni(), ni(), ni(), ni()
  max := 0
  for k := 0; k*a <= n; k++ {
    k2, noerr := dioph(b, c, n-k*a)
    if noerr && k+k2 > max {
      max = k + k2
    }
  }
  pri(max)
  w.Flush()
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	line, _ := Readln(reader)
	numbers := readIntArray(line)

	length := numbers[0]
	lengths := numbers[1:]

	cache := make(map[int]int, 0)
	fmt.Println(Cut(length, lengths, 0, cache))
}

func Cut(length int, lengths []int, pieces int, cache map[int]int) int {

	if cached, ok := cache[length]; ok {
		return cached
	}

	maxPieces := pieces
	isCut := false
	for _, ln := range lengths {
		if (length - ln) >= 0 {
			newPieces := Cut(length - ln, lengths, pieces + 1, cache)
			if maxPieces < newPieces {
				isCut = true
				maxPieces = newPieces
			}
		}
	}

	if (!isCut) && length > 0 {
		maxPieces = -1
		cache[length] = maxPieces
	} else if isCut {
		cache[length] = maxPieces
	}

	return maxPieces
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	line, _ := Readln(reader)
	numbers := readIntArray(line)

	length := numbers[0]
	lengths := numbers[1:]

	cache := make(map[int]int, 0)
	fmt.Println(Cut(length, lengths, 0, cache))
}

func Cut(length int, lengths []int, pieces int, cache map[int]int) int {

	if cached, ok := cache[length]; ok {
		return cached
	}

	maxPieces := pieces
	isCut := false
	for _, ln := range lengths {
		if (length - ln) >= 0 {
			isCut = true
			newPieces := Cut(length - ln, lengths, pieces + 1, cache)
			if maxPieces < newPieces {
				maxPieces = newPieces
			}
		}
	}

	if (isCut == false) && length > 0 {
		maxPieces = -1
		cache[length] = maxPieces
	} else if isCut {
		cache[length] = maxPieces
	}

	return maxPieces
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	line, _ := Readln(reader)
	numbers := readIntArray(line)

	length := numbers[0]
	lengths := numbers[1:]

	cache := make(map[int]int, 0)
	fmt.Println(Cut(length, lengths, 0, cache))
}

func Cut(length int, lengths []int, pieces int, cache map[int]int) int {

	if cached, ok := cache[length]; ok {
		return cached
	}

	maxPieces := pieces
	isCut := false
	for _, ln := range lengths {
		if (length - ln) >= 0 {
			isCut = true
			newPieces := Cut(length - ln, lengths, pieces + 1, cache)
			if maxPieces < newPieces {
				maxPieces = newPieces
			}
		}
	}

	if (isCut == false) && length > 0 {
		maxPieces = -1
	}

	cache[length] = maxPieces

	return maxPieces
}

package main

import "fmt"

func sortThree(a, b, c int) (int, int, int) {
	if a > b {
		a, b = b, a
	}
	if b > c {
		b, c = c, b
	}
	if a > b {
		a, b = b, a
	}
	return a, b, c
}

// https://codeforces.com/problemset/problem/189/A
// комментарии к решению
// Задача решается перебором. Для сокращения кол-ва комбинаций
// пытаемся сначала разрезать ленту на максимальное кол-во мелких кусочков,
// уменьшая их кол-во с каждой итерацией пробуем разрезать оставшуюся часть
// на ленты среднего размера, проводя аналогичный критерий выбора для
// среднего/крупного размера.
// Первое найденное целочисленное решение и будет ответом
func taskSolution(n, a, b, c int) int {
	a, b, c = sortThree(a, b, c)
	for i := n / a; i >= 0; i -= 1 {
		for j := (n - i*a) / b; j >= 0; j -= 1 {
			for k := (n - i*a - j*b) / c; k >= 0; k -= 1 {
				if n == i*a+j*b+k*c {
					return i + j + k
				}
			}
		}
	}
	return 0
}

func main() {
	var n, a, b, c int
	if _, err := fmt.Scan(&n, &a, &b, &c); err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(n, a, b, c))
}

package main

import (
	"fmt"
)

func main() {
	var n,a,b,c int
	s:=0
	fmt.Scan(&n,&a,&b,&c)
	for i:=0;i<=n/a;i++ {
		z:=n-i*a
		for k:=0; k<=z/b;k++ {
			h:=i+k+(z-k*b)/c
			if (z-k*b)%c!=0 && h>s {
				s=h
			}
		}
	}
	fmt.Println(s)
}

// http://codeforces.com/problemset/problem/189/A
package main

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

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

const (
	MOD = 1e9 + 7
)

type (

)

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

	return b
}

func main () {
	var (
		n, a, b, c int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &a, &b, &c)

	dp := make([]struct{cnt, l int}, 1e4 + 1)

	dp[0].l = n
	dp[0].l = n
	dp[0].l = n

	for i := 0; i <= n; i++ {

		if dp[i].l - a == a || dp[i].l - a == b || dp[i].l - a == c || dp[i].l - a == 0{
			if dp[i].cnt + 1 > dp[i + a].cnt {
				dp[i + a].cnt = dp[i].cnt + 1
				dp[i + a].l = dp[i].l - a
			}
		}

		if dp[i].l - b == a || dp[i].l - b == b || dp[i].l - b == c || dp[i].l - b == 0{
			if dp[i].cnt + 1 > dp[i + b].cnt {
				dp[i + b].cnt = dp[i].cnt + 1
				dp[i + b].l = dp[i].l - b
			}
		}

		if dp[i].l - c == a || dp[i].l - c == b || dp[i].l - c == c || dp[i].l - c == 0{
			if dp[i].cnt + 1 > dp[i + c].cnt {
				dp[i + c].cnt = dp[i].cnt + 1
				dp[i + c].l = dp[i].l - c
			}
		}

	}

	fmt.Println(max(max(dp[n].cnt, dp[n].cnt), dp[n].cnt))
}

package main

import "fmt"

func main() {
    var n int
    var a [3]int
    fmt.Scan(&n,&a[0],&a[1],&a[2])
    dp := make([]int,n+1)
    dp[0] = 1
    for k := 0; k < 3; k++ {
        for i := 1; i <= n; i++ {
            if (i-a[k]) >= 0 {
                dp[i] += dp[i-a[k]]
            }
        }
    }
    fmt.Println(dp[n])
}

package main

import "fmt"
import "sort"

func main() {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	var maxP int
	ls := []int{a, b, c}
	sort.Sort(sort.Reverse(sort.IntSlice(ls)))
	fmt.Println(ls)
	var i, j, k int
	for i = 0; i <= n/ls[0]; i++ {
		for j = 0; j <= n/ls[1]; j++ {
			for k = 0; k <= n/ls[2]; k++ {
				if n == i*ls[0]+j*ls[1]+k*ls[2] {
					if maxP < i+j+k {
						maxP = i + j + k
					}
				}
			}
		}
	}
	fmt.Print(maxP)
}


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	a, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	b, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	r, _ := strconv.Atoi(scanner.Text())

	if a >= r*2 && b >= r*2 {
		fmt.Printf("First\n")
	} else {
		fmt.Printf("Second\n")
	}
}

package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	a, b, r := scanInt(scanner), scanInt(scanner), scanInt(scanner)
	if a >= 2*r && b >= 2*r {
		writer.WriteString("First\n")
	} else {
		writer.WriteString("Second\n")
	}
}

package main

import "fmt"

func main() {
	a, b, r := 0, 0, 0
	fmt.Scanf("%d %d %d\n", &a, &b, &r)
	if a >= r*2 && b >= r*2 {
		fmt.Printf("First\n")
	} else {
		fmt.Printf("Second\n")
	}
}

package main

import (
	"fmt"
)

func main() {
	a, b, r := 0, 0, 0
	fmt.Scanf("%d %d %d\n", &a, &b, &r)
	winner := "Second"
	var xDiameter float32
	if a > b {
		xDiameter = float32(a) / float32(r*2)
	} else {
		xDiameter = float32(b) / float32(r*2)
	}
	if xDiameter >= 1 && int32((xDiameter-1)/1.5)%2 == 0 {
		winner = "First"
	}
	fmt.Printf("%s\n", winner)
}