There were $$$n$$$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $$$x$$$ swords of each type. $$$y$$$ people have broken into the theater basement and each of them has taken exactly $$$z$$$ swords of some single type. Note that different people might have taken different types of swords. Note that the values $$$x, y$$$ and $$$z$$$ are unknown for you.The next morning the director of the theater discovers the loss. He counts all swords — exactly $$$a_i$$$ swords of the $$$i$$$-th type are left untouched.The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.For example, if $$$n=3$$$, $$$a = [3, 12, 6]$$$ then one of the possible situations is $$$x=12$$$, $$$y=5$$$ and $$$z=3$$$. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values $$$x, y$$$ and $$$z$$$ beforehand but know values of $$$n$$$ and $$$a$$$.Thus he seeks for your help. Determine the minimum number of people $$$y$$$, which could have broken into the theater basement, and the number of swords $$$z$$$ each of them has taken.

The first line of the input contains one integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^{5})$$$ — the number of types of swords. The second line of the input contains the sequence $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^{9})$$$, where $$$a_i$$$ equals to the number of swords of the $$$i$$$-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices $$$(j, k)$$$ that $$$a_j \neq a_k$$$.

Print two integers $$$y$$$ and $$$z$$$ — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.

NoteIn the first example the minimum value of $$$y$$$ equals to $$$5$$$, i.e. the minimum number of people who could have broken into the basement, is $$$5$$$. Each of them has taken $$$3$$$ swords: three of them have taken $$$3$$$ swords of the first type, and two others have taken $$$3$$$ swords of the third type.In the second example the minimum value of $$$y$$$ is $$$1$$$, i.e. the minimum number of people who could have broken into the basement, equals to $$$1$$$. He has taken $$$7$$$ swords of the first type.

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	number, _ := strconv.Atoi(scanner.Text())
	array := make([]int64, number)
	for i := 0; i < number; i++ {
		scanner.Scan()
		array[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	y, z := calculate(array)
	fmt.Println(y, z)
}

func calculate(a []int64) (int64, int64) {
	var max, gcdr, people int64
	for _, v := range a {
		if v > max {
			max = v
		}
	}

	for _, v := range a {
		gcdr = gcd(max-v, gcdr)
	}

	for _, v := range a {
		people += (max - v) / gcdr
	}

	return people, gcdr
}

func gcd(a, b int64) int64 {
	for a > 1 && b > 1 {
		if a > b {
			a %= b
		} else {
			b %= a
		}
	}
	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}
	return 1
}

package main

import (
    "fmt"
    "bufio"
    "os"
)
var input *bufio.Reader

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

func GCD(x, y int64) int64 {
    for y != 0 {
        x, y = y, x%y
    }
    return x
}

func solve() {
    var (
        N int64
        i int64
        res int64
        arr_gcd int64
        maximum int64
    )
    fmt.Fscanf(input, "%d\n", &N)
    arr := make([]int64, N)
    for i=0 ; i<N ; i++ {
        fmt.Fscanf(input, "%d ", &arr[i])
    }
    fmt.Fscanf(input, "\n")
    maximum = max(arr)
    for i=0 ; i<N ; i++ {
        arr[i] = maximum - arr[i]
    }
    arr_gcd = arr[0]
    for i=1 ; i<N ; i++ {
        if arr[i] != 0 {
            arr_gcd = GCD(arr_gcd, arr[i])
        }
    }
    for i=0 ; i<N ; i++ {
        res += arr[i] / arr_gcd
    }
    fmt.Println(res,arr_gcd)
}

func main () {
    input = bufio.NewReader(os.Stdin)
    solve()
}

package main

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

const BufferSize = 20 * 2 * 100000

type InputReader struct {
	buf []byte
	cursor int
	size int
}

func (inputReader *InputReader) init() {
	inputReader.buf, _ = ioutil.ReadAll(os.Stdin)
	inputReader.size = len(inputReader.buf)
}

func (inputReader *InputReader) readInt() int {
	inputReader.skip()
	if inputReader.eof() {
		panic("Can not read")
	}

	sign := 1
	if inputReader.buf[inputReader.cursor] == '-' {
		sign *= -1
	}

	ret := 0
	for inputReader.cursor < inputReader.size && unicode.IsDigit(rune(inputReader.buf[inputReader.cursor])) {
		ret = 10 * ret + int(inputReader.buf[inputReader.cursor]) - int('0');
		inputReader.cursor ++
	}
	return ret
}

func (inputReader *InputReader) skip() {
	for inputReader.cursor < inputReader.size && unicode.IsSpace(rune(inputReader.buf[inputReader.cursor])) {
		inputReader.cursor ++
	}
}

func (inputReader *InputReader) eof() bool {
	return inputReader.cursor >= inputReader.size
}

const N = 300000
var a [N]int64

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a % b)
}

func main() {

	//var p int
	//fmt.Scanf("%d", &p)
	//fmt.Print(p)

	//buf, _ := ioutil.ReadAll(os.Stdin)
	//fmt.Print(buf)

	input := InputReader{}
	input.init()
	n := input.readInt()

	for i := 0; i < n; i++ {
		a[i] = int64(input.readInt())
	}

	var maxA int64 = -1
	for i := 0; i < n; i++ {
		if a[i] > maxA {
			maxA = a[i]
		}
	}

	var ansZ = maxA - a[0]
	for i := 1; i < n; i++ {
		ansZ = gcd(ansZ, maxA- a[i])
	}

	var ansY int64 = 0
	for i := 0; i < n; i++ {
		ansY += (maxA - a[i]) / ansZ
	}
	fmt.Printf("%d %d\n", ansY, ansZ)
}

package main

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

/*********** 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+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// 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 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())
}

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
}

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

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	m := Max(A...)
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = m - A[i]
	}

	C := []int{}
	for i := 0; i < n; i++ {
		if B[i] != 0 {
			C = append(C, B[i])
		}
	}

	if len(C) == 0 {
		fmt.Println(0, 0)
		return
	} else if len(C) == 1 {
		fmt.Println(1, C[0])
		return
	}

	g := Gcd(C[0], C[1])
	for i := 2; i < len(C); i++ {
		g = Gcd(g, C[i])
	}
	z := g
	// y := Sum(C...) / g
	y := int64(0)
	for i := 0; i < len(C); i++ {
		y += int64(C[i] / g)
	}
	fmt.Println(y, z)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

func main() {
	defer Flush()

	n, a := readIntsll(0)
	_ = n
	var maxa, mina int64
	mina = math.MaxInt64
	for _, v := range a {
		maxa = maxll(maxa, v)
		mina = minll(mina, v)
	}
	if mina == maxa {
		panic("mina==maxa")
	}

	z := maxa - mina
	for _, v := range a {
		x := maxa - v
		z = gcdll(z, x)
	}
	var y int64
	for _, v := range a {
		y += (maxa - v) / z
	}
	println(y, z)

}

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

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

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

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

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// 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"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []Pair) []Pair {
	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].first > arr[right].first {
			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 sort2(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]

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

func gcd (a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd (b, a % b);
}

func solution(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	mm := int64(INF)
	mma := -int64(INF)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		if a[i] < mm {
			mm = a[i]
		}
		if a[i] > mma {
			mma = a[i]
		}
	}
	y := mma - mm
	for i := 0; i < n; i++ {
		if a[i] - mm > 0 {
			y = gcd(y, a[i] - mm)
		}
	}
	var x int64
	for i := 0; i < n; i++ {
		x += (mma - a[i]) / y
	}
	fmt.Println(x, y)

}

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanln(in, &n)
	a := make([]int, n)
	var sum int64 = 0
	var max = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		sum += int64(a[i])
		if a[i] > max {
			max = a[i]
		}
	}
	z := abs(a[0] - a[1])
	for i := 2; i < n; i++ {
		z = gcd(z, abs(a[i] - a[i-1]))
	}
	y := (int64(max) * int64(n) - sum) / int64(z)

	fmt.Print(y, " ", z)
}

package main

import "fmt"

func main() {
	var number int
	fmt.Scan(&number)
	array := make([]int, number)
	for i := 0; i < number; i++ {
		fmt.Scan(&array[i])
	}
	y, z := calculate(array)
	fmt.Println(y, z)
}

func calculate(a []int) (int, int) {
	max := 0
	for _, v := range a {
		if v > max {
			max = v
		}
	}

	gcdr := 0
	for _, v := range a {
		gcdr = gcd(max-v, gcdr)
	}

	people := 0
	for _, v := range a {
		people += (max - v) / gcdr
	}

	return people, gcdr
}

func gcd(a, b int) int {
	for a > 1 && b > 1 {
		if a > b {
			a %= b
		} else {
			b %= a
		}
	}
	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}
	return 1
}

package main

import (
    "fmt"
    "bufio"
    "os"
)
var input *bufio.Reader

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

func GCD(x, y int64) int64 {
    for y != 0 {
        x, y = y, x%y
    }
    return x
}

func solve() {
    var (
        N int64
        i int64
        res int64
        arr_gcd int64
        maximum int64
    )
    fmt.Fscanf(input, "%d\n", &N)
    arr := make([]int64, N)
    for i=0 ; i<N ; i++ {
        fmt.Fscanf(input, "%d ", &arr[i])
    }
    fmt.Fscanf(input, "\n")
    maximum = max(arr)
    for i=0 ; i<N ; i++ {
        arr[i] = maximum - arr[i]
    }
    arr_gcd = arr[0]
    for i=1 ; i<N ; i++ {
        if arr[i] != 0 {
            arr_gcd = GCD(arr_gcd, arr[i])
        }
    }
    for i=0 ; i<N ; i++ {
        res += arr[i] / arr_gcd
    }
    fmt.Println(res,arr_gcd)
}

func main () {
    input = bufio.NewReader(os.Stdin)
    solve()
}

package main

import "fmt"

const N = 300000
var a [N]int64

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a % b)
}

func main() {
	var n int
	var maxA int64 = -1
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		if i == n - 1 {
			fmt.Scanf("%d", &a[i])
		} else {
			fmt.Scanf("%d", &a[i])
		}
		fmt.Print(a[i], "\n")
		if a[i] > maxA {
			maxA = a[i]
		}
	}

	var ansZ = maxA - a[0]
	for i := 1; i < n; i++ {
		ansZ = gcd(ansZ, maxA- a[i])
	}

	var ansY int64 = 0
	for i := 0; i < n; i++ {
		ansY += (maxA - a[i]) / ansZ
	}
	fmt.Printf("%d %d\n", ansY, ansZ)
}

package main

import "fmt"

const N = 300000
var a [N]int

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

func main() {
	var n int
	var max_a = -1
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if a[i] > max_a {
			max_a = a[i]
		}
	}

	ans_z := max_a - a[0]
	for i := 1; i < n; i++ {
		ans_z = gcd(ans_z, max_a - a[i])
	}

	ans_y := 0
	for i := 0; i < n; i++ {
		ans_y += (max_a - a[i]) / ans_z
	}
	fmt.Printf("%d %d\n", ans_y, ans_z)
}

package main

import "fmt"

const N = 300000
var a [N]int64

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a % b)
}

func main() {
	var n int
	var maxA int64 = -1
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		if i == n - 1 {
			fmt.Scanf("%d\n", &a[i])
		} else {
			fmt.Scanf("%d ", &a[i])
		}
		if a[i] > maxA {
			maxA = a[i]
		}
	}

	var ansZ = maxA - a[0]
	for i := 1; i < n; i++ {
		ansZ = gcd(ansZ, maxA- a[i])
	}

	var ansY int64 = 0
	for i := 0; i < n; i++ {
		ansY += int64((maxA - a[i]) / ansZ)
	}
	fmt.Printf("%d %d\n", ansY, ansZ)
}

package main

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

/*********** 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+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// 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 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())
}

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
}

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

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	m := Max(A...)
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = m - A[i]
	}

	C := []int{}
	for i := 0; i < n; i++ {
		if B[i] != 0 {
			C = append(C, B[i])
		}
	}

	if len(C) == 0 {
		fmt.Println(0, 0)
		return
	} else if len(C) == 1 {
		fmt.Println(1, C[0])
		return
	}

	g := Gcd(C[0], C[1])
	for i := 2; i < len(C); i++ {
		g = Gcd(g, C[i])
	}
	z := g
	// y := Sum(C...) / g
	y := 0
	for i := 0; i < len(C); i++ {
		y += C[i] / g
	}
	fmt.Println(y, z)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

/*********** 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+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// 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 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())
}

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
}

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

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	m := Max(A...)
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = m - A[i]
	}

	C := []int{}
	for i := 0; i < n; i++ {
		if B[i] != 0 {
			C = append(C, B[i])
		}
	}

	if len(C) == 0 {
		fmt.Println(0, 0)
		return
	} else if len(C) == 1 {
		fmt.Println(1, C[0])
		return
	}

	g := Gcd(C[0], C[1])
	for i := 2; i < len(C); i++ {
		g = Gcd(g, C[i])
	}
	z := g
	y := Sum(C...) / g
	fmt.Println(y, z)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

/*********** 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+11)) // for AtCoder
	r.Buffer(make([]byte, 2048), int(1e+9)) // for Codeforces
	// 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 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())
}

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
}

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

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	m := Max(A...)
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = m - A[i]
	}

	C := []int{}
	for i := 0; i < n; i++ {
		if B[i] != 0 {
			C = append(C, B[i])
		}
	}

	if len(C) == 0 {
		fmt.Println(0, 0)
		return
	} else if len(C) == 1 {
		fmt.Println(1, C[0])
		return
	}

	g := Gcd(C[0], C[1])
	for i := 2; i < len(C); i++ {
		g = Gcd(g, C[i])
	}
	z := g
	y := Sum(C...) / g
	fmt.Println(y, z)
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []Pair) []Pair {
	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].first > arr[right].first {
			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 sort2(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]

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

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

func solution(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	mm := INF
	mma := -INF
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		if a[i] < mm {
			mm = a[i]
		}
		if a[i] > mma {
			mma = a[i]
		}
	}
	y := mma - mm
	for i := 0; i < n; i++ {
		if a[i] - mm > 0 {
			y = gcd(y, a[i] - mm)
		}
	}
	var x int
	for i := 0; i < n; i++ {
		x += (mma - a[i]) / y
	}
	fmt.Println(x, y)

}

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 (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []Pair) []Pair {
	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].first > arr[right].first {
			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 sort2(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]

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

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

func solution(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	mm := INF
	mma := -INF
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		if a[i] < mm {
			mm = a[i]
		}
		if a[i] > mma {
			mma = a[i]
		}
	}
	y := -1
	for i := 0; i < n; i++ {
		if a[i] - mm > 0 {
			if y == -1 {
				y = a[i] - mm
			} else {
				y = gcd(y, a[i] - mm)
			}
		}
	}
	var x int
	for i := 0; i < n; i++ {
		x += (mma - a[i]) / y
	}
	fmt.Println(x, y)

}

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


Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.The text is a string $$$s$$$ of lowercase Latin letters. She considers a string $$$t$$$ as hidden in string $$$s$$$ if $$$t$$$ exists as a subsequence of $$$s$$$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $$$1$$$, $$$3$$$, and $$$5$$$, which form an arithmetic progression with a common difference of $$$2$$$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $$$S$$$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!For example, in the string aaabb, a is hidden $$$3$$$ times, b is hidden $$$2$$$ times, ab is hidden $$$6$$$ times, aa is hidden $$$3$$$ times, bb is hidden $$$1$$$ time, aab is hidden $$$2$$$ times, aaa is hidden $$$1$$$ time, abb is hidden $$$1$$$ time, aaab is hidden $$$1$$$ time, aabb is hidden $$$1$$$ time, and aaabb is hidden $$$1$$$ time. The number of occurrences of the secret message is $$$6$$$.

The first line contains a string $$$s$$$ of lowercase Latin letters ($$$1 \le |s| \le 10^5$$$) — the text that Bessie intercepted.

Output a single integer  — the number of occurrences of the secret message.

NoteIn the first example, these are all the hidden strings and their indice sets:   a occurs at $$$(1)$$$, $$$(2)$$$, $$$(3)$$$  b occurs at $$$(4)$$$, $$$(5)$$$  ab occurs at $$$(1,4)$$$, $$$(1,5)$$$, $$$(2,4)$$$, $$$(2,5)$$$, $$$(3,4)$$$, $$$(3,5)$$$  aa occurs at $$$(1,2)$$$, $$$(1,3)$$$, $$$(2,3)$$$  bb occurs at $$$(4,5)$$$  aab occurs at $$$(1,3,5)$$$, $$$(2,3,4)$$$  aaa occurs at $$$(1,2,3)$$$  abb occurs at $$$(3,4,5)$$$  aaab occurs at $$$(1,2,3,4)$$$  aabb occurs at $$$(2,3,4,5)$$$  aaabb occurs at $$$(1,2,3,4,5)$$$  Note that all the sets of indices are arithmetic progressions.In the second example, no hidden string occurs more than once.In the third example, the hidden string is the letter l.

package main

import (
	"fmt"
)

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

	// scanner.Scan()
	// s := scanner.Text()
	var s string
	fmt.Scanf("%s", &s)
	fmt.Println(solve(s))
}

func solve(s string) int64 {
	dp := make([]int64, 26)
	fp := make([][]int64, 26)

	for i := 0; i < 26; i++ {
		fp[i] = make([]int64, 26)
	}

	n := len(s)

	for i := n - 1; i >= 0; i-- {
		x := int(s[i] - 'a')

		for j := 0; j < 26; j++ {
			fp[x][j] += dp[j]
		}

		dp[x]++
	}

	var res int64
	for i := 0; i < 26; i++ {
		res = max(res, dp[i])
		for j := 0; j < 26; j++ {
			res = max(res, fp[i][j])
		}
	}

	return res
}

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

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 100010)

	s := NextBytes()
	n := len(s)
	var pairsCount [26][26]int64
	charCount := make([]int64, 26)
	for i := 0; i < n; i++ {
		ch := int(s[i]) - int('a')
		for j := 0; j < 26; j++ {
			pairsCount[j][ch] += charCount[j]
		}
		charCount[ch]++
	}
	var res int64
	for i := 0; i < 26; i++ {
		if charCount[i] > res {
			res = charCount[i]
		}
		for j := 0; j < 26; j++ {
			if pairsCount[i][j] > res {
				res = pairsCount[i][j]
			}
		}
	}
	fmt.Fprintln(out, res)
}

/*
URL:
https://codeforces.com/problemset/problem/1307/C
*/

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
	// MOD          = 998244353
	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 (
	S []rune

	memo map[string]int64
	cnts map[rune]int64
)

func main() {
	S = ReadRuneSlice()

	memo = make(map[string]int64)
	cnts = make(map[rune]int64)
	for _, r := range S {
		str := fmt.Sprintf("%c", r)
		memo[str]++
		cnts[r]++
	}

	for i := 0; i < len(S); i++ {
		r := S[i]
		cnts[r]--
		for nr := 'a'; nr <= 'z'; nr++ {
			cnt := cnts[nr]
			str := fmt.Sprintf("%c%c", r, nr)
			memo[str] += cnt
		}
	}

	ans := int64(0)
	for _, v := range memo {
		ChMax(&ans, v)
	}
	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

func solve() {
}

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

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

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

	var s string
	fmt.Fscanf(reader, "%s", &s)

	ans := int64(0)
	mp := make(map[int]int64)
	for i := 0; i < len(s); i++ {
		for c := byte('a'); c <= byte('z'); c++ {
			cc := mp[int(c-'a'+1)]
			mp[int(s[i]-'a'+1)+100*int(c-'a'+1)] += cc
			ans = max(ans, mp[int(s[i]-'a'+1)+100*int(c-'a'+1)])
		}
		mp[int(s[i]-'a'+1)]++
		ans = max(ans, mp[int(s[i]-'a'+1)])
	}

	fmt.Println(ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1307C(_r io.Reader, _w io.Writer) {
	s, _ := ioutil.ReadAll(_r)
	s = bytes.TrimSpace(s)
	cnt := [26]int64{}
	cntPair := [26][26]int64{}
	for _, b := range s {
		b -= 'a'
		for i, c := range cnt {
			cntPair[i][b] += c
		}
		cnt[b]++
	}
	ans := int64(0)
	for _, c := range cnt {
		if c > ans {
			ans = c
		}
	}
	for _, cp := range cntPair {
		for _, c := range cp {
			if c > ans {
				ans = c
			}
		}
	}
	Fprint(_w, ans)
}

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

package main;

import "fmt"

type int = int64

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

func bin_up(a []int, need int) int {
	var l, r int = -1, int(len(a))
	for r - l > 1 {
		var mid int = (l + r) / 2
		if a[mid] <= need {
			l = mid
		} else {
			r = mid
		}
	}
	return r
}

func bin_low(a []int, need int) int {
	var l, r int = -1, int(len(a))
	for r - l > 1 {
		var mid int = (l + r) / 2
		if a[mid] < need {
			l = mid
		} else {
			r = mid
		}
	}
	return r
}

func main() {
	var s string
	fmt.Scan(&s)
	var n int = int(len(s))
	var ind [][]int = make([][]int, 26)
	for i := int(0); i < n; i++ {
		ind[s[i] - 'a'] = append(ind[s[i] - 'a'], i)
	}
 	var ans int = 0
	for st := 0; st < 26; st++ {
		for end := 0; end < 26; end++ {
			if st == end {
				ans = max(ans, int(len(ind[st])))
				var now_ans int = 0
				for _, el := range ind[st] {
					var res int = bin_up(ind[end], el)
					if res != int(len(ind[end])) {
						now_ans += int(len(ind[end])) - res
					}
				}
				ans = max(ans, now_ans)
			} else {
				var now_ans int = 0
				for _, el := range ind[st] {
					var res int = bin_low(ind[end], el)
					if res != int(len(ind[end])) {
						now_ans += int(len(ind[end])) - res
					}
				}
				ans = max(ans, now_ans)
			}
		}
	}
	fmt.Println(ans)
}

package main

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

var dp [27][27] int64
var a [27] int64
var ans int64

func main() {
	s := ReadString()
	for i := 0; i < len(s); i++ {
		//fmt.Println(s[i])
		for j := 0; j < 26; j++ {
			dp[j][s[i]-'a'] += a[j]
			ans = max(ans, dp[j][s[i]-'a'])
		}
		a[s[i]-'a']++
		ans = max(ans, a[s[i]-'a'])
	}
	fmt.Println(ans)
}
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

package main

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

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

	scanner.Scan()
	s := scanner.Text()
	fmt.Println(solve(s))
}

func solve(s string) int64 {
	dp := make([]int64, 26)
	fp := make([][]int64, 26)

	for i := 0; i < 26; i++ {
		fp[i] = make([]int64, 26)
	}

	n := len(s)

	for i := n - 1; i >= 0; i-- {
		x := int(s[i] - 'a')

		for j := 0; j < 26; j++ {
			fp[x][j] += dp[j]
		}

		dp[x]++
	}

	var res int64
	for i := 0; i < 26; i++ {
		res = max(res, dp[i])
		for j := 0; j < 26; j++ {
			res = max(res, fp[i][j])
		}
	}

	return res
}

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

package main

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

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

	var s string
	fmt.Fscanf(reader, "%s", &s)

	ans := 0
	mp := make(map[int]int)
	for i := 0; i < len(s); i++ {
		for c := byte('a'); c <= byte('z'); c++ {
			cc := mp[int(c-'a'+1)]
			mp[int(s[i]-'a'+1)+26*int(c-'a'+1)] += cc
			ans = max(ans, mp[int(s[i]-'a'+1)+100*int(c-'a'+1)])
		}
		mp[int(s[i]-'a'+1)]++
		ans = max(ans, mp[int(s[i]-'a'+1)])
	}

	fmt.Println(ans)
}

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

package main

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

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

	var s string
	fmt.Fscanf(reader, "%s", &s)

	ans := 0
	mp := make(map[int]int)
	for i := 0; i < len(s); i++ {
		for c := byte('a'); c <= byte('z'); c++ {
			cc := mp[int(c-'a'+1)]
			mp[int(s[i]-'a'+1)+26*int(c-'a'+1)] += cc
			ans = max(ans, mp[int(s[i]-'a'+1)+26*int(c-'a'+1)])
		}
		mp[int(s[i]-'a'+1)]++
		ans = max(ans, mp[int(s[i]-'a'+1)])
	}

	fmt.Println(ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1307C(_r io.Reader, _w io.Writer) {
	s, _ := ioutil.ReadAll(_r)
	s = bytes.TrimSpace(s)
	cnt := [26]int64{}
	cntPair := [26][26]int64{}
	for _, b := range s {
		b -= 'a'
		cnt[b]++
		for i, c := range cnt {
			cntPair[i][b] += c
		}
	}
	ans := int64(0)
	for _, c := range cnt {
		if c > ans {
			ans = c
		}
	}
	for i, cp := range cntPair {
		for j, c := range cp {
			if i != j && c > ans {
				ans = c
			}
		}
	}
	Fprint(_w, ans)
}

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

package main;

import "fmt"

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

func bin_up(a []int, need int) int {
	var l, r int = -1, len(a)
	for r - l > 1 {
		var mid int = (l + r) / 2
		if a[mid] <= need {
			l = mid
		} else {
			r = mid
		}
	}
	return r
}

func bin_low(a []int, need int) int {
	var l, r int = -1, len(a)
	for r - l > 1 {
		var mid int = (l + r) / 2
		if a[mid] < need {
			l = mid
		} else {
			r = mid
		}
	}
	return r
}

func main() {
	var s string
	fmt.Scan(&s)
	var n int = len(s)
	var ind [][]int = make([][]int, 26)
	for i := 0; i < n; i++ {
		ind[s[i] - 'a'] = append(ind[s[i] - 'a'], i)
	}
 	var ans int = 0
	for st := 0; st < 26; st++ {
		for end := 0; end < 26; end++ {
			if st == end {
				ans = max(ans, len(ind[st]))
				var now_ans int = 0
				for _, el := range ind[st] {
					var res int = bin_up(ind[end], el)
					if res != len(ind[end]) {
						now_ans += len(ind[end]) - res
					}
				}
				ans = max(ans, now_ans)
			} else {
				var now_ans int = 0
				for _, el := range ind[st] {
					var res int = bin_low(ind[end], el)
					if res != len(ind[end]) {
						now_ans += len(ind[end]) - res
					}
				}
				ans = max(ans, now_ans)
			}
		}
	}
	fmt.Println(ans)
}


Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func max(a,b int) int {
	if a>b {
		return a
	} else {
		return b
	}
}

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

func main() {
	var n,x,ma,mi,a,b int
	input:=bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	mi=-1
	ma=100000
	fmt.Scan(&n,&x)
	for i:=0;i<n;i++ {
		input.Scan()
		aa,_:=strconv.Atoi(input.Text())
		a=aa
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		b=bb
		mi=max(mi,min(a,b))
		ma=min(ma,max(a,b))
	}
	if mi>ma {
		fmt.Println("-1")
	} else if mi<=x && x<=ma {
		fmt.Println("0")
	} else {
		if x<mi {
			fmt.Println(mi-x)
		}else {
			fmt.Println(x-ma)
		}
	}
}

package main

import "fmt"

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

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

func main() {
	var n, x0 int
	fmt.Scanf("%d %d\n", &n, &x0)
	var a, b = 0, 1001
	for i := 0; i < n; i++ {
		var s, e int
		fmt.Scanf("%d %d\n", &s, &e)
		if e < s {
			s, e = e, s
		}
		a = max(a, s)
		b = min(b, e)
	}
	if a > b {
		fmt.Println(-1)
	} else {
		if x0 < a {
			fmt.Println(a - x0)
		} else if b < x0 {
			fmt.Println(x0 - b)
		} else {
			fmt.Println(0)
		}
	}
}

package main

import "fmt"

func isset(mask int64, i int) bool {
	return (mask & (1 << uint8(i))) != 0
}

func set(mask *int64, i int) {
	*mask = *mask | (1 << uint8(i))
}

func unset(mask *int64, i int) {
	if isset(*mask, i) {
		*mask = *mask ^ (1 << uint8(i))
	}
}

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

func main() {
	var n, x0 int
	fmt.Scanf("%d %d\n", &n, &x0)
	var row [1024]int
	for i := 0; i < n; i++ {
		var s, e int
		fmt.Scanf("%d %d\n", &s, &e)
		if e < s {
			s, e = e, s
		}

		if s <= x0 && x0 <= e {
			continue
		}
		for j := s; j <= e; j++ {
			row[j] = i + 1
		}
	}

	var leftMask int64
	for i := x0 - 1; i >= 0; i-- {
		if row[i] != 0 {
			set(&leftMask, row[i])
		}
	}

	var rightMask int64
	for i := x0 + 1; i <= 1000; i++ {
		if row[i] != 0 {
			set(&rightMask, row[i])
		}
	}

	var leftDist int64
	for i := x0 - 1; i >= 0 && leftMask != 0; i-- {
		if row[i] != 0 {
			unset(&leftMask, row[i])
		}
		leftDist++
	}

	var rightDist int64
	for i := x0 + 1; i <= 1000 && rightMask != 0; i++ {
		if row[i] != 0 {
			unset(&rightMask, row[i])
		}
		rightDist++
	}

	var ans = min(rightDist+rightDist+leftDist, leftDist+leftDist+rightDist)

	fmt.Println(ans)
}


The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring.

The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B. All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.

Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists.

NoteIn the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1.

package main

import "os"
import "bufio"
import "strconv"
import "sort"
import "math"
import "fmt"

func main(){
	var n, m, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
	}
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	y := make([]int, m)
	for i:=0; i<m; i++ {
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
	}
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	z := make([]int, k)
	for i:=0; i<k; i++ {
		r.Scan()
		z[i], _ = strconv.Atoi(r.Text())
	}
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	sort.Ints(x)
	sort.Ints(y)
	sort.Ints(z)
	fmt.Printf("%.12f\n", float64(x[n-1])*math.Sqrt(float64(float64(b*y[m-1])/float64(a*z[0]+b*y[m-1]))))
}

package main

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

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()
	n := scanInt(scanner)
	xs := make([]int, n)
	for i := range xs {
		xs[i] = scanInt(scanner)
	}
	sort.Ints(xs)
	m := scanInt(scanner)
	ys := make([]int, m)
	for i := range ys {
		ys[i] = scanInt(scanner)
	}
	sort.Ints(ys)
	k := scanInt(scanner)
	zs := make([]int, k)
	for i := range zs {
		zs[i] = scanInt(scanner)
	}
	sort.Ints(zs)
	A, B := scanInt(scanner), scanInt(scanner)
	r1, p1, p2 := xs[n-1], ys[m-1], zs[0]
	r2 := math.Sqrt(float64(r1*r1) / (1.0 + float64(A*p2)/float64(B*p1)))
	writer.WriteString(fmt.Sprintf("%f\n", r2))
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,m,k int
    var A,B,f float64
    r1, p1, p2 := float64(0), float64(0), float64(5000)
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&f)
        if r1 < f { r1 = f }
    }
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        fmt.Scan(&f)
        if p1 < f { p1 = f }
    }
    fmt.Scan(&k)
    for i := 0; i < k; i++ {
        fmt.Scan(&f)
        if p2 > f { p2 = f }
    }
    fmt.Scan(&A,&B)
    fmt.Println(r1*math.Sqrt((B*p1)/((B*p1)+(A*p2))))
}

// 215B-mic
package main

import (
	"fmt"
	"math"
)

func main() {
	var d, p1, r1, p2, a, b float64
	var n, i int
	p2 = 1e9 + 7
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&d)
		r1 = math.Max(r1, d)
	}
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&d)
		p1 = math.Max(p1, d)
	}
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&d)
		p2 = math.Min(p2, d)
	}
	fmt.Scan(&a, &b)
	fmt.Printf("%.9f\n", float64(r1*float64(math.Sqrt((b*p1)/(b*p1+a*p2)))))
}