Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar).

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the length of each wooden bar. The second line contains a single integer a (1 ≤ a ≤ n) — the length of the vertical (left and right) sides of a door frame. The third line contains a single integer b (1 ≤ b ≤ n) — the length of the upper side of a door frame.

Print the minimal number of wooden bars with length n which are needed to make the frames for two doors.

NoteIn the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed.

package main

import (
	"fmt"
	"sort"
)

func next_permutation(idx []int) bool {
	n := len(idx)
	for i := n - 1; i >= 1; i-- {
		if idx[i] > idx[i-1] {
			idx[i], idx[i-1] = idx[i-1], idx[i]
			sort.Ints(idx[i:])
			return true
		}
	}

	return false
}

func main() {
	var n, a, b int
	fmt.Scanf("%d\n%d\n%d", &n, &a, &b)
	frames := make([]int, 6)
	idxs := make([]int, 6)
	for i := 0; i < 6; i++ {
		if i < 4 {
			frames[i] = a
		} else {
			frames[i] = b
		}
		idxs[i] = i
	}

	bestAnswer := 6
	for {
		count, leftover := 0, 0
		for i := 0; i < 6; i++ {
			if leftover < frames[idxs[i]] {
				count++
				leftover = n
			}
			leftover -= frames[idxs[i]]
		}
		if count < bestAnswer {
			bestAnswer = count
		}
		if !next_permutation(idxs) {
			break
		}
	}

	fmt.Println(bestAnswer)
}

package main

import (
  "fmt"
)

var n int32
var a int32
var b int32

func ReadData() {
  fmt.Scan(&n);
  fmt.Scan(&a);
  fmt.Scan(&b);
}

func Solve(na int32, nb int32, current int32, dbg bool) int {
  if na == 0 && nb == 0 {
    return 0;
  }

  var r0 int = 10000;
  var r1 int = 10000;
  var r2 int = 10000;
  var mode int = 4;

  if 0 < na && a <= current {
    r0 = Solve(na - 1, nb, current - a, false);
  }
  if 0 < nb && b <= current {
    r1 = Solve(na, nb - 1, current - b, false);
  }
  if current != n {
    r2 = 1 + Solve(na, nb, n, false);
  }

  result := r0
  mode = 0
  if r1 < result {
    result = r1
    mode = 1
  }
  if r2 < result {
    result = r2
    mode = 2
  }

  if dbg {
    if mode == 0 {
      Solve(na - 1, nb, current - a, true);
    } else if mode == 1 {
      Solve(na, nb - 1, current - b, true);
    } else if mode == 2 {
    r2 = 1 + Solve(na, nb, n, true);
    }
    fmt.Println("na: ", na, " nb: ", nb, " current: ", current, " result: ", result, " mode: ", mode)
  }
  return result
}

func main() {
  ReadData();
  fmt.Println(Solve(4, 2, 0, false));
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, a, b int
	fmt.Scanf("%d\n%d\n%d", &n, &a, &b)
	frames := make([]int, 6)
	for i := 0; i < 6; i++ {
		if i < 4 {
			frames[i] = a
		} else {
			frames[i] = b
		}
	}
	sort.Ints(frames)
	count := 0
	leftover := 0

	for i := 0; i < 6; i++ {
		if leftover >= frames[i] {
			leftover -= frames[i]
			continue
		}
		if i > 0 {
			if leftover+frames[i-1]-frames[i] >= 0 {
				count++
				leftover = n - frames[i-1]
				continue
			}
		}
		count++
		leftover = n - frames[i]
	}
	fmt.Println(count)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, a, b int
	fmt.Scanf("%d\n%d\n%d", &n, &a, &b)
	frames := make([]int, 6)
	for i := 0; i < 6; i++ {
		if i < 4 {
			frames[i] = a
		} else {
			frames[i] = b
		}
	}
	sort.Ints(frames)
	count := 0
	leftover := 0

	for i := 0; i < 6; i++ {
		if leftover >= frames[i] {
			leftover -= frames[i]
			continue
		}
		if i > 0 {
			if leftover+frames[i-1]-frames[i] >= 0 {
				count++
				leftover = n - frames[i]
				continue
			}
		}
		count++
		leftover = n - frames[i]
	}
	fmt.Println(count)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, a, b int
	fmt.Scanf("%d\n%d\n%d", &n, &a, &b)
	frames := make([]int, 6)
	for i := 0; i < 6; i++ {
		if i < 4 {
			frames[i] = a
		} else {
			frames[i] = b
		}
	}
	sort.Ints(frames)
	count := 0
	leftover := 0

	for i := 0; i < 6; i++ {
		if leftover >= frames[i] {
			leftover -= frames[i]
			continue
		}
		if i > 0 {
			if leftover+frames[i-1]+frames[i] >= 0 {
				count++
				leftover = n - frames[i-1]
				continue
			}
		}
		count++
		leftover = n - frames[i]
	}
	fmt.Println(count)
}

package main

import (
  "fmt"
)

var n int32
var a int32
var b int32

func ReadData() {
  fmt.Scanf("%d", &n);
  fmt.Scanf("%d", &a);
  fmt.Scanf("%d", &b);
}

func Solve(na int32, nb int32, current int32) int {
  if na == 0 && nb == 0 {
    return 0;
  }

  var r0 int = 1000;
  var r1 int = 1000;
  var r2 int = 1000;

  if 0 < na && a <= current {
    r0 = Solve(na - 1, nb, current - a);
  }
  if 0 < nb && b <= current {
    r1 = Solve(na, nb - 1, current - b);
  }
  if current < a && current < b {
    r2 = 1 + Solve(na, nb, n);
  }
  result := r0
  if r1 < result {
    result = r1
  }
  if r2 < result {
    result = r2
  }

  return result
}

func main() {
  ReadData();
  fmt.Println(Solve(4, 2, 0));
}

package main

import (
  "fmt"
)

var n int32
var a int32
var b int32

func ReadData() {
  fmt.Scanf("%d", &n);
  fmt.Scanf("%d", &a);
  fmt.Scanf("%d", &b);
}

func Solve(na int32, nb int32, current int32) int {
  if na == 0 && nb == 0 {
    return 0;
  }

  var r0 int = 1000;
  var r1 int = 1000;
  var r2 int = 1000;

  if 0 < na && a <= current {
    r0 = Solve(na - 1, nb, current - a);
  }
  if 0 < nb && b <= current {
    r1 = Solve(na, nb - 1, current - b);
  }
  if n != current {
    r2 = 1 + Solve(na, nb, n);
  }
  result := r0
  if r1 < result {
    result = r1
  }
  if r2 < result {
    result = r2
  }

  return result
}

func main() {
  ReadData();
  fmt.Println(Solve(4, 2, 0));
}

package main

import (
  "fmt"
)

var n int32
var a int32
var b int32

func ReadData() {
  fmt.Scanf("%d", &n);
  fmt.Scanf("%d", &a);
  fmt.Scanf("%d", &b);
}

func Solve(na int32, nb int32, current int32) int {
  if na == 0 && nb == 0 {
    return 0;
  }

  var result int = 1000;
  var r0 int = 1000;
  var r1 int = 1000;
  var r2 int = 1000;

  if 0 < na && a <= current {
    r0 = Solve(na - 1, nb, current - a);
  }
  if 0 < nb && b <= current {
    r1 = Solve(na, nb - 1, current - b);
  }
  if n != current {
    r2 = 1 + Solve(na, nb, n);
  }
  result = r0
  if r1 < r0 {
    result = r1
  }
  if r2 < result {
    result = r2
  }

  return result
}

func main() {
  ReadData();
  fmt.Println(1 + Solve(4, 2, n));
}

package main

import (
  "fmt"
)

var n int32
var a int32
var b int32

func ReadData() {
  fmt.Scanf("%d", &n);
  fmt.Scanf("%d", &a);
  fmt.Scanf("%d", &b);
}

func Solve(na int32, nb int32, current int32, dbg bool) int {
  if na == 0 && nb == 0 {
    return 0;
  }

  var r0 int = 10000;
  var r1 int = 10000;
  var r2 int = 10000;
  var mode int = 4;

  if 0 < na && a <= current {
    r0 = Solve(na - 1, nb, current - a, false);
  }
  if 0 < nb && b <= current {
    r1 = Solve(na, nb - 1, current - b, false);
  }
  if current != n {
    r2 = 1 + Solve(na, nb, n, false);
  }

  result := r0
  mode = 0
  if r1 < result {
    result = r1
    mode = 1
  }
  if r2 < result {
    result = r2
    mode = 2
  }

  if dbg {
    if mode == 0 {
      Solve(na - 1, nb, current - a, true);
    } else if mode == 1 {
      Solve(na, nb - 1, current - b, true);
    } else if mode == 2 {
    r2 = 1 + Solve(na, nb, n, true);
    }
    fmt.Println("na: ", na, " nb: ", nb, " current: ", current, " result: ", result, " mode: ", mode)
  }
  return result
}

func main() {
  ReadData();
  fmt.Println(Solve(4, 2, 0, false));
}


Arpa is researching the Mexican wave.There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.   At time 1, the first spectator stands.  At time 2, the second spectator stands.  ...  At time k, the k-th spectator stands.  At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.  At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.  ...  At time n, the n-th spectator stands and the (n - k)-th spectator sits.  At time n + 1, the (n + 1 - k)-th spectator sits.  ...  At time n + k, the n-th spectator sits. Arpa wants to know how many spectators are standing at time t.

The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).

Print single integer: how many spectators are standing at time t.

NoteIn the following a sitting spectator is represented as -, a standing spectator is represented as ^.  At t = 0  ----------  number of standing spectators = 0.  At t = 1  ^---------  number of standing spectators = 1.  At t = 2  ^^--------  number of standing spectators = 2.  At t = 3  ^^^-------  number of standing spectators = 3.  At t = 4  ^^^^------  number of standing spectators = 4.  At t = 5  ^^^^^-----  number of standing spectators = 5.  At t = 6  -^^^^^----  number of standing spectators = 5.  At t = 7  --^^^^^---  number of standing spectators = 5.  At t = 8  ---^^^^^--  number of standing spectators = 5.  At t = 9  ----^^^^^-  number of standing spectators = 5.  At t = 10 -----^^^^^  number of standing spectators = 5.  At t = 11 ------^^^^  number of standing spectators = 4.  At t = 12 -------^^^  number of standing spectators = 3.  At t = 13 --------^^  number of standing spectators = 2.  At t = 14 ---------^  number of standing spectators = 1.  At t = 15 ----------  number of standing spectators = 0.

// Codeforces helper functions
// 20 Jan 18
// samadhi

package main

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

const debug = true

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

	in := gsli(reader)

	n := in[0]
	k := in[1]
	t := in[2]

	ans := 0
	if t <= k {
		ans = t
	} else if t <= n {
		ans = k
	} else {
		ans = k + n - t
	}

	fmt.Println(ans)

}

// Input helpers

// If you don't pass in a reference to the reader, and just instantiate a new
// one every time, it will work locally, with IO typed at human-speed, but not
// on Codeforces.

// Get Space-separated Line as Strings
//
// Example input:
// 1 test 382.0
// Example output:
// ["1", "test", "382.0"]

func gsls(reader *bufio.Reader) (arr []string) {
	// Get a full line
	input, _ := reader.ReadString('\n')

	//Strip newline and return chars, if any
	input = strings.TrimSuffix(input, "\n")
	input = strings.TrimSuffix(input, "\r")

	// Split at the spaces into an array
	arr = strings.Split(input, " ")

	return
}

// Get Space-separated Line as Integers
// Any non-valid integers will be 0
//
// Example input:
// test 1 12.3 -117
// Example output:
// [0, 1, 0, -117]

func gsli(reader *bufio.Reader) (arr []int) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.Atoi(e)
		arr = append(arr, cur)
	}

	return
}

// Get Space-separated Line as 64-bit Floats
// Any non-valid floats will be 0
//
// Example input:
// test 128.328 12 -11.0
// Example output:
// [0, 128.328, 12, -11]

func gslf(reader *bufio.Reader) (arr []float64) {
	stringArr := gsls(reader)

	for _, e := range stringArr {
		cur, _ := strconv.ParseFloat(e, 64)
		arr = append(arr, cur)
	}

	return
}

// String helpers

// Is Lowercase
// Given some string[i], return whether it is lower case or not.

func isl(b byte) bool {
	var r rune
	r = rune(b)
	return unicode.IsLower(r)
}

// Math helpers

// Positve Modulo
// Returns x mod y, but always positive

func posMod(x, y int) int {
	return (x%y + y) % y
}

// Max Int
// Returns the max of two ints

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

// Distance formule
// Calculates the distance to the origin

func dist(x, y float64) float64 {
	return math.Sqrt(math.Pow(x, 2) + math.Pow(y, 2))
}

// Output helpers

func yes() {
	fmt.Println("Yes")
}

func no() {
	fmt.Println("No")
}

// Debug helpers

// From https://groups.google.com/forum/#!topic/golang-nuts/Qlxs3V77nss

func dbg(s string, a ...interface{}) {
	if debug {
		fmt.Printf(s, a...)
	}
}

package main

import (
        "fmt"
)

var (
        n int
        k int
        t int
)

func main() {
        fmt.Scanf("%d %d %d\n", &n, &k, &t)
        if t <= k {
                fmt.Println(t)
        } else if t >= n {
                fmt.Println(n + k - t)
        } else {
                fmt.Println(k)
        }
}

package main

import "fmt"

func main(){
	var n,k,t int
	fmt.Scanf("%d %d %d",&n,&k,&t)
	if t<=k{
		fmt.Println(t)
	} else{
		if t<=n {
			fmt.Println(k)
		}else {
			fmt.Println(k-(t-n))
		}
	}
}

package main

import "fmt"

func main() {
	l := []int{0, 0, 0}
	fmt.Scan(&l[0], &l[1], &l[2])
	r := l[0] + l[1] - l[2]
	for _, x := range l {
		if r > x {
			r = x
		}
	}
	fmt.Println(r)
}

package main

import "fmt"

func main() {
	var n, k, t int
	fmt.Scan(&n, &k, &t)
	if n < t {
		n += k - t
	}
	if n > k {
		n = k
	}
	fmt.Println(n)
}


A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....   The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.

The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).  The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.

NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.

package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	if _, err := fmt.Scanf("%d %d\n%d %d\n", &a, &b, &c, &d); err != nil {
		return
	}

	offset := make(map[int]bool)

	for i := 0; ; i++ {
		t := i*a + b
		if t-d >= 0 {
			if (t-d)%c == 0 {
				fmt.Println(t)
				return
			}
			l := (t - d) / c
			off := t - (l*c + d)
			if offset[off] {
				break
			} else {
				offset[off] = true
			}
		}
	}

	fmt.Println(-1)
}

/*
URL:
https://codeforces.com/problemset/problem/787/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	a, b, c, d int
)

func main() {
	a, b, c, d = ReadInt4()

	for i := 0; i <= 3000; i++ {
		for j := 0; j <= 3000; j++ {
			if b+i*a == d+j*c {
				fmt.Println(b + i*a)
				return
			}
		}
	}
	fmt.Println(-1)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func solve() {
	a := readInt()
	b := readInt()
	c := readInt()
	d := readInt()
	for i := 0; i < 100000; i++ {
		if i >= b && i >= d {
			if (i-b)%a == 0 && (i-d)%c == 0 {
				fmt.Println(i)
				return
			}
		}
	}
	fmt.Println(-1)
}

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 min(a int, 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 (
	"fmt"
)

func main() {
	var a, b, c, d, i int
	var arr1, arr2 []int
	var flag bool
	fmt.Scanf("%d %d\n%d %d", &a, &b, &c, &d)
	for i != 6000 {
		arr1 = append(arr1, b+(i*a))
		arr2 = append(arr2, d+(i*c))
		i++
	}
	for i := range arr1 {
		for j := range arr2 {
			if arr1[i] == arr2[j] {
				fmt.Println(arr1[i])
				flag = true
				break
			}
		}
		if flag {
			break
		}
	}
	if !flag {
		fmt.Println("-1")
	}
}

package main

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

func main() {
	var i, tmp int
	var arr1, arr2 []int
	var arr3 [4]int
	var flag bool
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ := reader.ReadString('\n')
	arrS := strings.Split(strings.TrimSpace(line), " ")
	for i := range arrS {
		tmp, _ = strconv.Atoi(arrS[i])
		arr3[i] = tmp
	}
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for i := range arrS {
		tmp, _ = strconv.Atoi(arrS[i])
		arr3[i+2] = tmp
	}
	i = 0
	for i != 6000 {
		arr1 = append(arr1, arr3[1]+(i*arr3[0]))
		arr2 = append(arr2, arr3[3]+(i*arr3[2]))
		i++
	}
	i = 0
	for j := range arr1 {
		x := arr1[j]
		i := sort.Search(len(arr2), func(i int) bool { return arr2[i] >= x })
		if i < len(arr2) && arr2[i] == x {
			writer.WriteString(strconv.Itoa(x))
			flag = true
			break
		}
	}
	if !flag {
		writer.WriteString("-1")
	}
	writer.Flush()
}

package main
import ."fmt"

func main(){
    var a , b , c , d int
    Scanf("%d%d\n" , &a , &b)
    Scanf("%d%d" , &c , &d)
    mapper := make([]int , 1e6+5)
    for i:=b; i<= 1e6; i+=a{
        mapper[i] += 1
    }
    ans := -1
    for i:=d; i<= 1e6; i+=c{
        mapper[i] += 1
        if mapper[i] == 2{
            ans = i
            break
        }
    }
    Printf("%d" , ans)
}

package main

import "fmt"
import "os"

func main(){
	var a , b , c , d int
	fmt.Scanf("%d%d\n" , &a , &b)
	fmt.Scanf("%d%d" , &c , &d)
	for i:=0 ; i<=110 ; i++ {
		if (b+i*a-d) % c == 0 && b+i*a-d >= 0 {
			fmt.Printf("%d\n" ,b+i*a)
			os.Exit(0)
		}
	}
	fmt.Printf("-1\n")
}

package main

import "fmt"
import "os"

func main(){
	var a , b , c , d int
	fmt.Scanf("%d%d%d%d" , a , b , c , d)
	if b == d {
		fmt.Printf("%d\n", d)
		os.Exit(0)
	}
	for i:=0 ; i<=110 ; i++ {
		if (b+i*a-d) % c == 0 {
			fmt.Printf("%d\n" ,b+i*a)
			os.Exit(0)
		}
	}
	fmt.Printf("-1\n")
}

package main

import "fmt"
import "os"

func main(){
	var a , b , c , d int
	fmt.Scanf("%d%d\n" , &a , &b)
	fmt.Scanf("%d%d" , &c , &d)
	for i:=0 ; i<=110 ; i++ {
		if (b+i*a-d) % c == 0 {
			fmt.Printf("%d\n" ,b+i*a)
			os.Exit(0)
		}
	}
	fmt.Printf("-1\n")
}


Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.

The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.

First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices. Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.

NoteIf you need clarification of what parallelogram is, please check Wikipedia page:https://en.wikipedia.org/wiki/Parallelogram

package main

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

func main() {
	type Tuple        struct {
		x int
		y int
	}
	sc := NewScanner()
	X := make([]int, 3)
	Y := make([]int, 3)

	for i := 0; i < 3; i++ {
		X[i], Y[i] = sc.NextInt(), sc.NextInt()
	}
	mp := map[Tuple]bool{}
	for i := 0; i < 3; i++ {
		for j := i + 1; j < 3; j++ {
			x := X[i] - X[j]
			y := Y[i] - Y[j]

			for k := 0; k < 3; k++ {
				if k == i || k == j {
					continue
				}
				mp[Tuple{X[k] + x, Y[k] + y}] = true
				mp[Tuple{X[k] - x, Y[k] - y}] = true
			}
		}
	}
	fmt.Println(len(mp))
	for k, _ := range mp {
		fmt.Println(k.x, k.y)
	}

}

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

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

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

func main() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var x1 int
	for I(&x1, " ") == nil {
		solve(x1)
	}
}
func solve(x1 int) {
	var y1, x2, y2, x3, y3 int
	I(&y1, "\n")
	I(&x2, " ")
	I(&y2, "\n")
	I(&x3, " ")
	I(&y3, "\n")
	O(3, "\n")
	O(x1+x2-x3, " ")
	O(y1+y2-y3, "\n")
	O(x1-x2+x3, " ")
	O(y1-y2+y3, "\n")
	O(-x1+x2+x3, " ")
	O(-y1+y2+y3, "\n")
}

package main

import (
	"fmt"
)

func main() {
	var xy [3][2]int

	for i := 0; i < 3; i++ {
		if _, err := fmt.Scanf("%d %d\n", &xy[i][0], &xy[i][1]); err != nil {
			return
		}
	}

	fmt.Println(3)
	for i := 0; i < 3; i++ {
		var c, o [2]int
		for j := 0; j < 3; j++ {
			if j != i {
				for k := 0; k < 2; k++ {
					c[k] += xy[j][k]
				}
			}
		}
		for k := 0; k < 2; k++ {
			o[k] = c[k] - xy[i][k]
		}

		fmt.Println(o[0], o[1])
	}
}

// Codeforces 749 B training
// int - 32 bit type !!!!
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
    var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for i:=0; i<len(ss); i++ {
        a[i], err = strconv.Atoi(ss[i])
        if err != nil {
            fmt.Println("n atoi failure", err)
            panic(err)
        }
    }
    return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
    a := make([]int, n)
    s, err := in.ReadString('\n')
    if err != nil {
        fmt.Println("read failure", err)
        panic(err)
    }
    ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for j:=0; j<n; j++ {
        aa,err := strconv.Atoi(ss[j])
        if err != nil {
            fmt.Println("aa conv failed", err)
            panic(err)
        }
        a[j] = aa
    }
    return a
}

type point struct {
	x,y int
}
var n int
var pa,pb,pc point
var rp []point

func readPoint() point {
	x,y,_,_,_ := readFive()
	p := point{x,y}
	return p
}

func printPoint(p point) {
	fmt.Printf("%d %d\n", p.x, p.y)
}

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading s
    pa = readPoint()
    pb = readPoint()
    pc = readPoint()
}

func fourthPoint(a point,b,c point) point {
	xx := b.x + c.x - a.x;
	yy := b.y + c.y - a.y;
	p := point{xx,yy}
	return p
}

func solve() {
	n = 3
	rp = make([]point, n)
	rp[0] = fourthPoint(pa, pb, pc)
	rp[1] = fourthPoint(pb, pc, pa)
	rp[2] = fourthPoint(pc, pa, pb)
}

func printRes() {
	fmt.Println(n)
	for i:=0; i<n; i++ {
		printPoint(rp[i])
	}
}

func main() {
 	readData()
    solve()
    printRes()
}

package main

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

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

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

func main() {
	x1, y1 := results()
	x2, y2 := results()
	x3, y3 := results()
	fmt.Println("3")
	fmt.Println(x2-x1+x3, y2-y1+y3)
	fmt.Println(x3-x2+x1, y3-y2+y1)
	fmt.Println(x1-x3+x2, y1-y3+y2)
}

func results() (int, int) {
	scanner.Scan()
	result := strings.Fields(scanner.Text())
	x, err1 := strconv.Atoi(result[0])
	y, err2 := strconv.Atoi(result[1])
	if err1 == nil && err2 == nil {
		return x, y
	} else {
		return 0, 0
	}
}

package main

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

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

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

func main() {
	//var x1 ,x2,x3,y1,y2,y3 int
	scanner.Scan()
	words := strings.Fields(scanner.Text())
	scanner.Scan()
	words = strings.Fields(scanner.Text())
	fmt.Println(words[0])
	fmt.Println(words[1])
	//fmt.Println("3")
	//fmt.Println(x2-x1+x3, y2-y1+y3)
	//fmt.Println(x3-x2+x1, y3-y2+y1)
	//fmt.Println(x1-x3+x2, y1-y3+y2)
}

package main

import (
	"fmt"
)

func main() {
	var x1 ,x2,x3,y1,y2,y3 int
	fmt.Scanf("%d %d", &x1, &y1)
	fmt.Scanf("%d %d", &x2, &y2)
	fmt.Scanf("%d %d", &x3, &y3)
	fmt.Println("3")
	fmt.Println(y1)
	fmt.Println(x2-x1+x3, y2-y1+y3)
	fmt.Println(x3-x2+x1, y3-y2+y1)
	fmt.Println(x1-x3+x2, y1-y3+y2)
}

package main

import (
	"fmt"
)

func main() {
	var x1 ,x2,x3,y1,y2,y3 int
	fmt.Scanf("%d %d", &x1, &y1)
	fmt.Scanf("%d %d", &x2, &y2)
	fmt.Scanf("%d %d", &x3, &y3)
	fmt.Println("3")
	fmt.Printf("%d ", x2-x1+x3)
	fmt.Printf("%d ", y2-y1+y3)
	fmt.Println()
	fmt.Printf("%d ", x3-x2+x1)
	fmt.Printf("%d ", y3-y2+y1)
	fmt.Println()
	fmt.Printf("%d ", x1-x3+x2)
	fmt.Printf("%d ", y1-y3+y2)
}

package main

import (
	"fmt"
)

func main() {
	var x1 ,x2,x3,y1,y2,y3 int
	fmt.Scanf("%d%d", &x1, &y1)
	fmt.Scanf("%d%d", &x2, &y2)
	fmt.Scanf("%d%d", &x3, &y3)
	fmt.Println("3")
	fmt.Println(x2-x1+x3, y2-y1+y3)
	fmt.Println(x3-x2+x1, y3-y2+y1)
	fmt.Println(x1-x3+x2, y1-y3+y2)
}

package main

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

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

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

func main() {
	//var x1 ,x2,x3,y1,y2,y3 int
	scanner.Scan()
	words := strings.Fields(scanner.Text())
	fmt.Println(words[0])
	fmt.Println(words[1])
	//fmt.Println("3")
	//fmt.Println(x2-x1+x3, y2-y1+y3)
	//fmt.Println(x3-x2+x1, y3-y2+y1)
	//fmt.Println(x1-x3+x2, y1-y3+y2)
}

package main

import (
	"fmt"
)

func main() {
	var x1 ,x2,x3,y1,y2,y3 int
	fmt.Scanf("%d", &x1)
	fmt.Scanf("%d", &y1)
	fmt.Scanf("%d", &x2)
	fmt.Scanf("%d", &y2)
	fmt.Scanf("%d", &x3)
	fmt.Scanf("%d", &y3)
	fmt.Println("3")
	fmt.Println(x2-x1+x3, y2-y1+y3)
	fmt.Println(x3-x2+x1, y3-y2+y1)
	fmt.Println(x1-x3+x2, y1-y3+y2)
}

package main

import (
	"fmt"
)

func main() {
	var x1 ,x2,x3,y1,y2,y3 int
	fmt.Scanf("%d %d", &x1, &y1)
	fmt.Scanf("%d %d", &x2, &y2)
	fmt.Scanf("%d %d", &x3, &y3)
	fmt.Println("3")
	fmt.Println(x2-x1+x3, y2-y1+y3)
	fmt.Println(x3-x2+x1, y3-y2+y1)
	fmt.Println(x1-x3+x2, y1-y3+y2)
}