package main

import (
  "fmt"
)

func max(x, y int64) int64 {
  if (x < y) {
    return y
  } else {
    return x
  }
}

func main() {
  var t int

  fmt.Scan(&t)

  var a,b,c int64

  for t > 0 {
    //fmt.Println(t)
    var temp float64

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

    //fmt.Println(a,b,c)

    temp = float64(c-a+b)/2
    //fmt.Println(temp,c)

    if temp < 0 {
      fmt.Println(c+1)
    } else {
      fmt.Println(max(0,c-int64(temp)))
    }

    t -= 1
  }

}

package main

import "fmt"

func main() {
	var T, s, i, e int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		fmt.Scan(&s, &i, &e)
		least := (s+i+e)/2 + 1
		if s+e < least {
			fmt.Println(0)
			continue
		}
		ans := min(e+1, s+e-least+1)
		fmt.Println(ans)
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

package main

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

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

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)

	var t int
	fmt.Fscanf(reader, "%d\n", &t)

	for i := 0; i < t; i++ {
		var ss, ii, ee int64
		fmt.Fscanf(reader, "%d %d %d\n", &ss, &ii, &ee)
		if ss <= ii {
			ee -= (ii - ss)
			ss = ii
			if ee <= 0 {
				fmt.Println(0)
			} else {
				if ee % 2 == 0 {
					fmt.Println(ee / 2)
				} else {
					fmt.Println((ee + 1) / 2)
				}
			}
		} else {
			if ss - ii > ee {
				fmt.Println(ee + 1)
			} else {
				sss := ss - ii + (ee - (ss - ii) + 1)  / 2
				fmt.Println(sss)
			}

		}
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1217/problem/A

package main

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

func Solve(str int, intel int, exp int) int {
	if str+exp < intel {
		return 0
	}
	if intel+exp < str {
		return exp + 1
	}
	x := (intel + exp - str) / 2
	return exp - x
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	fmt.Fscanf(reader, "%d\n", &T)
	for i := 0; i < T; i++ {
		var str, intel, exp int
		fmt.Fscanf(reader, "%d %d %d\n", &str, &intel, &exp)
		fmt.Fprintf(writer, "%d\n", Solve(str, intel, exp))
	}
}

package main

import (
    "fmt"
)

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

func Min(x, y int) int {
    if x < y {
        return x
    } else {
        return y
    }
}

func main() {
    var t int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        var s, i, e int
        fmt.Scan(&s, &i, &e)
        fmt.Println(Min(e + 1, Max(0, (s + e - i + 1) / 2)))
    }
}

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		s, i, e := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &s, &i, &e)
		if i > s {
			e -= i - s
			s = i
			if e <= 0 {
				fmt.Fprintf(out, "%d\n", 0)
				continue
			}
		}
		x := 0
		x = (i + e - s) / 2
		for 2*x <= i+e-s {
			x++
		}
		if x < 0 {
			x = 0
		}
		//fmt.Println("debug", s, i, e, x)
		fmt.Fprintf(out, "%d\n", e-x+1)
	}
	return
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}

package main

import "fmt"

func main() {
	var T, str, intv, exp int
	fmt.Scanln(&T)
	for a:=0; a < T; a++ {
		fmt.Scanln(&str, &intv, &exp)
		if str+exp <= intv {
			fmt.Println(0)
		} else {
			ans := 0
			if str <= intv {
				exp = exp-(intv-str)
				str = intv
			}
			if str > intv {
				if str-intv > exp {
					ans = exp+1
					exp = 0
				} else {
					ans = str-intv
					exp -= str-intv
				}
			}
			if exp == 0 {
				fmt.Println(ans)
			} else {
				if exp%2 == 0 {
					fmt.Println(exp/2+ans)
				}else {
					fmt.Println(exp/2+ans+1)
				}
			}
		}
	}
}

package main

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

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	var n, a, b, c int
	fmt.Fscanf(reader, "%d\n", &n)
	for ; n != 0; n-- {
		fmt.Fscanf(reader, "%d%d%d\n", &a, &b, &c)

		a += c
		if a <= b {
			fmt.Println(0)
			continue
		}
		c++
		if c > (a-b+1)/2 {
			fmt.Println((a - b + 1) / 2)
		} else {
			fmt.Println(c)
		}
	}
}

/*
2
3 1 1
2 1 0
*/

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		st := readi()
		in := readi()
		ex := readi()
		println(solve(st, in, ex))
	}

}

func solve(st, in, ex int) int {

	k := sort.Search(ex+1, func(e int) bool {
		//eprintln(st, in, ex, e, in < st+e)
		return in+(ex-e) < st+e
	})
	return ex - k + 1
}

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

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

func main() {
	var t, a, b, c int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c)

		lo := 0
		hi := c

		var lo2 int
		if b + c - a < 0 {
			lo2 = (b + c - a) / 2
		} else {
			lo2 = (b + c - a) / 2 + 1
		}
		if lo2 > lo {
			lo = lo2
		}

		answer := 0
		if lo <= hi {
			answer = hi - lo + 1
		}

		fmt.Println(answer)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

	if exp <= 0 {
		if str > int {
			return 1
		} else {
			return 0
		}
	}

	if (str - int) > exp {
		return exp + 1
	}

	exp -= (int-str)

	if exp <= 0 {
		return 0
	}

	if exp%2 == 1 {
		return exp/2 + 1
	} else {
		return exp/2
	}

	return 0
}

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		s, i, e := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &s, &i, &e)
		if i > s {
			e -= i - s
			s = i
			if e <= 0 {
				fmt.Fprintf(out, "%d\n", 0)
				continue
			}
		}
		x := 0
		x = (i + e - s) / 2
		if 2*x <= i+e-s {
			x++
		}
		//fmt.Println("debug", s, i, e, x)
		fmt.Fprintf(out, "%d\n", e-x+1)
	}
	return
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}

package main

import "fmt"

func main() {
	var T, str, intv, exp int
	fmt.Scanln(&T)
	for a:=0; a < T; a++ {
		fmt.Scanln(&str, &intv, &exp)
		if str+exp <= intv {
			fmt.Println(0)
		} else {
			ans := 0
			if str <= intv {
				exp = exp-(intv-str)
				str = intv
			}
			if str > intv {
				if str-intv > exp {
					ans = exp+1
				} else {
					ans = str-intv
					exp -= str-intv
				}
			}
			if exp == 0 {
				fmt.Println(ans)
			} else {
				if exp%2 == 0 {
					fmt.Println(exp/2+ans)
				}else {
					fmt.Println(exp/2+ans+1)
				}
			}
		}
	}
}

package main

import "fmt"

func main() {
	var T, str, intv, exp int
	fmt.Scanln(&T)
	for a:=0; a < T; a++ {
		fmt.Scanln(&str, &intv, &exp)
		if str+exp <= intv {
			fmt.Println(0)
		} else {
			ans := 0
			if str <= intv {
				exp = exp-(intv-str)
				str = intv
				ans = 1
			}
			if str > intv {
				if str-intv > exp {
					ans = exp+1
				} else {
					ans = str-intv+1
					exp -= str-intv
				}
			}
			if exp == 0 {
				fmt.Println(ans)
			} else {
				if exp%2 == 0 {
					fmt.Println(exp/2-1+ans)
				}else {
					fmt.Println(exp/2+ans)
				}
			}
		}
	}
}

package main

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

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	var n, a, b, c int
	fmt.Fscanf(reader, "%d\n", &n)
	for ; n != 0; n-- {
		fmt.Fscanf(reader, "%d%d%d\n", &a, &b, &c)
		if c == 0 && a > b {
			fmt.Println(1)
			continue
		}

		a += c
		if c > (a-b+1)/2 {
			c = (a - b + 1) / 2
		}
		fmt.Println(c)
	}
}

package main

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

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	var n, a, b, c int
	fmt.Fscanf(reader, "%d\n", &n)
	for ; n != 0; n-- {
		fmt.Fscanf(reader, "%d%d%d\n", &a, &b, &c)
		if c == 0 {
			if a > b {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
			continue
		}
		a += c
		if a <= b {
			fmt.Println(0)
			continue
		}
		if c > (a-b+1)/2 {
			fmt.Println((a - b + 1) / 2)
		} else {
			fmt.Println(c)
		}
	}
}

package main

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

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	var n, a, b, c int
	fmt.Fscanf(reader, "%d\n", &n)
	for ; n != 0; n-- {
		fmt.Fscanf(reader, "%d%d%d\n", &a, &b, &c)
		if c == 0 && a > b {
			fmt.Println(1)
			continue
		}

		a += c
		if (a-b+1)/2 < 0 {
			fmt.Println(0)
			continue
		}
		if c > (a-b+1)/2 {
			c = (a - b + 1) / 2
		}
		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, c int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c)

		diff := b - a + 1;
		if diff < 0 {
			diff = 0
		}

		answer := 0
		if c >= diff {
			c -= diff
			a += diff
			answer = (a - b + c) / 2 + (a - b + c) % 2;
		}

		fmt.Println(answer)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, c int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c)

		diff := b - a + 1;
		if diff < 0 {
			diff = 0
		}

		answer := 0
		if c >= diff {
			c -= diff
			a += diff
			answer = c / 2 + 1;
		}

		fmt.Println(answer)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, c int
	fmt.Scanf("%d", &t)
	for tc := 0; tc < t; tc++ {
		fmt.Scanf("%d %d %d", &a, &b, &c)

		diff := b - a + 1;
		if diff < 0 {
			diff = 0
		}

		answer := 0
		if c >= diff {
			c -= diff
			a += diff
			answer = c / 2 + 1;
		}

		fmt.Println(answer)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

	if exp <= 0 {
		if str > int {
			return 1
		} else {
			return 0
		}
	}

	exp -= (int-str)

	if exp <= 0 {
		return 0
	}

	if exp%2 == 1 {
		return exp/2 + 1
	} else {
		return exp/2
	}

	return 0
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

	exp -= (int-str)

	if exp <= 0 {
		return 0
	}

	if exp%2 == 1 {
		return exp/2 + 1
	} else {
		return exp/2
	}

	return 0
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

	if exp <= 0 {
		return 0
	}

	exp -= (int-str)

	if exp <= 0 {
		return 0
	}

	if exp%2 == 1 {
		return exp/2 + 1
	} else {
		return exp/2
	}

	return 0
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

	exp -= (int-str)

	if exp%2 == 1 {
		return exp/2 + 1
	} else {
		return exp/2
	}

	return 0
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstRow, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}

	var firstRowfields = strings.Fields(firstRow)
	n, err := strconv.Atoi(firstRowfields[0])
	if err != nil {
		log.Fatal(err)
	}

	for i := 0; i < n; i++ {
			line, err := reader.ReadString('\n')
			ints, err := parseInts(line)
		if err != nil {
			log.Fatal(err)
		}

		result := solution(ints[0], ints[1], ints[2])

		fmt.Println(result)
	}
}

func parseInts(s string) ([]int, error) {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
		err    error
	)
	for i, f := range fields {
		ints[i], err = strconv.Atoi(f)
		if err != nil {
			return nil, err
		}
	}
	return ints, nil
}

func solution(str int, int int, exp int) int {

    delta := str - int

	if exp <= 0 {
		if delta > 0 {
			return 1
		} else {
			return 0
		}
	}

	if delta > 0 {

		if delta > exp {
			return exp+1
		} else {
			delta = -delta
		}
	} else {
		exp -= delta

		if exp <= 0 {
			return 0
		}

		if exp%2 == 1 {
			return exp/2 + 1
		} else {
			return exp/2
		}
	}

	return 0
}

package main

import (
  "fmt"
)

func max(x, y int64) int64 {
  if (x < y) {
    return y
  } else {
    return x
  }
}

func main() {
  var t int

  fmt.Scan(&t)

  var a,b,c int64

  for t > 0 {
    //fmt.Println(t)
    var temp float32

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

    //fmt.Println(a,b,c)

    temp = float32(c-a+b)/2
    //fmt.Println(temp,c)

    if temp < 0 {
      fmt.Println(c+1)
    } else {
      fmt.Println(max(0,c-int64(temp)))
    }

    t -= 1
  }

}

// Author: sighduck
// URL: https://codeforces.com/contest/1217/problem/A

package main

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

func Solve(str int, intel int, exp int) int {
	if exp == 0 && str > intel {
		return 1
	} else if exp == 0 {
		return 0
	}
	x := (intel + exp - str) / 2
	if x > exp {
		return 0
	}
	if x < 0 {
		return exp
	}
	return exp - x
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	fmt.Fscanf(reader, "%d\n", &T)
	for i := 0; i < T; i++ {
		var str, intel, exp int
		fmt.Fscanf(reader, "%d %d %d\n", &str, &intel, &exp)
		fmt.Fprintf(writer, "%d\n", Solve(str, intel, exp))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1217/problem/A

package main

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

func Solve(str int, intel int, exp int) int {
	if exp == 0 && str > intel {
		return 1
	} else if exp == 0 {
		return 0
	}
	x := (intel + exp - str) / 2
	if x < 0 {
		return exp
	}
	return exp - x
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	fmt.Fscanf(reader, "%d\n", &T)
	for i := 0; i < T; i++ {
		var str, intel, exp int
		fmt.Fscanf(reader, "%d %d %d\n", &str, &intel, &exp)
		fmt.Fprintf(writer, "%d\n", Solve(str, intel, exp))
	}
}

package main

import (
    "fmt"
)

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

func main() {
    var t int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        var s, i, e int
        fmt.Scan(&s, &i, &e)
        fmt.Println(Max(0, (s + e - i + 1) / 2))
    }
}


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

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


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

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


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