package main

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

var DEBUG = true

func main() {
	defer Flush()
	n, b := readInts(0)
	_ = n
	var minv, minc, maxv, maxc int
	minv = b[0]
	maxv = b[0]

	for _, v := range b {
		if maxv <= v {
			if maxv < v {
				maxc = 0
			}
			maxv = v
			maxc++
		}
		if v <= minv {
			if v < minv {
				minc = 0
			}
			minv = v
			minc++
		}
	}

	println(maxv-minv, maxc*minc)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

var DEBUG = true

func main() {
	defer Flush()
	n, b := readInts(0)
	_ = n
	var minv, minc, maxv, maxc int
	minv = b[0]
	maxv = b[0]

	for _, v := range b {
		if maxv <= v {
			if maxv < v {
				maxc = 0
			}
			maxv = v
			maxc++
		}
		if v <= minv {
			if v < minv {
				minc = 0
			}
			minv = v
			minc++
		}
	}

	if minv == maxv {
		println(0, maxc*(maxc-1)/2)
	}

	println(maxv-minv, maxc*minc)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

var DEBUG = true

func main() {
	defer Flush()
	n, b := readInts(0)
	_ = n
	var maxc, minc int64
	var maxv, minv int
	minv = b[0]
	maxv = b[0]
	minc = 1
	maxc = 1

	for i := 1; i < n; i++ {
		v := b[i]
		if maxv <= v {
			if maxv < v {
				maxc = 0
			}
			maxv = v
			maxc++
		}
		if v <= minv {
			if v < minv {
				minc = 0
			}
			minv = v
			minc++
		}
	}

	if minv == maxv {
		println(0, maxc*(maxc-1)/2)
	}

	println(maxv-minv, maxc*minc)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

var DEBUG = true

func main() {
	defer Flush()
	n, b := readInts(0)
	_ = n
	var maxc, minc int64
	var maxv, minv int
	minv = b[0]
	maxv = b[0]
	minc = 1
	maxc = 1

	for i := 1; i < n; i++ {
		v := b[i]
		if maxv <= v {
			if maxv < v {
				maxc = 0
			}
			maxv = v
			maxc++
		}
		if v <= minv {
			if v < minv {
				minc = 0
			}
			minv = v
			minc++
		}
	}

	if minv == maxv {
		println(0, maxc*(maxc-1)/2)
		return
	}

	println(maxv-minv, maxc*minc)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    n,err = strconv.Atoi(strings.Trim(s," \n\r"))
    if err != nil {
        fmt.Println("atoi failure", err)
    }
   // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],err = strconv.Atoi(ss[i])
		if err != nil {
		    fmt.Println("ba atoi failure", err)
		}
    }

    // calculate min max ....
	var nmin,nmax int64
	minb := 20000000000
	maxb := -10000
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif := maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,_ := in.ReadString('\n')
    n,_ = strconv.Atoi(strings.Trim(s," \n"))
    // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],_ = strconv.Atoi(ss[i])
    }

    // calculate min max ....
	maxdif := 0
	nmin,nmax := 0,0
	minb := 2000000000
	maxb := -1;
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif = maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    n,err = strconv.Atoi(strings.Trim(s," \n\r"))
    if err != nil {
        fmt.Println("atoi failure", err)
    }
   // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],err = strconv.Atoi(ss[i])
		if err != nil {
		    fmt.Println("ba atoi failure", err)
		}
    }

    // calculate min max ....
	maxdif := 0
	nmin,nmax := 0,0
	minb := 2000000000
	maxb := -1;
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif = maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

import (
    "fmt"
)

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    var n int=0
    fmt.Scanf("%d\n", &n)
    // fmt.Println("read n =",n)
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        fmt.Scanf("%d", &(ba[i]))
    }
	maxdif := 0
	nmin,nmax := 0,0
	minb := 2000000000
	maxb := -1;
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif = maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    n,err = strconv.Atoi(strings.Trim(s," \n\r"))
    if err != nil {
        fmt.Println("atoi failure", err)
    }
   // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],err = strconv.Atoi(ss[i])
		if err != nil {
		    fmt.Println("ba atoi failure", err)
		}
    }

    // calculate min max ....
	var nmin,nmax int64
	minb := 2000000000
	maxb := -10000
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif := maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    n,err = strconv.Atoi(strings.Trim(s," \n"))
    if err != nil {
        fmt.Println("atoi failure", err)
    }
   // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],err = strconv.Atoi(ss[i])
		if err != nil {
		    fmt.Println("ba atoi failure", err)
		}
    }

    // calculate min max ....
	maxdif := 0
	nmin,nmax := 0,0
	minb := 2000000000
	maxb := -1;
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	maxdif = maxb - minb
	fmt.Printf("%d %d\n",maxdif, nmin*nmax)
}


// Codeforces 459 B
package main

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

var nseg [10]int

func cntseg(v int) int {
    var sum int = 0
    for i:=0; i<11; i++ {
        if v > 0 {
            r := v % 10
            sum += nseg[r]
            v = v / 10
        }
    }
	return sum
}

func main() {
    // reading n
    var n int=0
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    n,err = strconv.Atoi(strings.Trim(s," \n\r"))
    if err != nil {
        fmt.Println("atoi failure", err)
    }
   // fmt.Println("read n =",n)

    // reading b
    s,_ = in.ReadString('\n')
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    ba := make([]int, n)
    for i:=0; i<n; i++ {
        ba[i],err = strconv.Atoi(ss[i])
		if err != nil {
		    fmt.Println("ba atoi failure", err)
		}
    }

    // calculate min max ....
	var nmin,nmax int64
	minb := 2000000000
	maxb := -10000
	for i:=0; i<n; i++ {
	    b := ba[i]
	    if b < minb {
	       minb = b
	       nmin = 1
	    } else if b==minb {
	       nmin++
	    }
	    if b > maxb {
	       maxb = b
	       nmax = 1
	    } else if b==maxb {
	       nmax++
	    }
	}
	var np int64
	var maxdif int
	if maxb==minb {
	    n64 := int64(n)
	    np = n64*(n64-1)/2
	    maxdif = 0
	} else {
		maxdif = maxb - minb
		np = nmin*nmax
	}
	fmt.Printf("%d %d\n",maxdif, np)
}


package main

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

func main() {
    var n, min, minnum, max, maxnum int
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    min = 1e9
    minnum = 0
    max = 0
    maxnum = 0
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    fmt.Println(max-min, maxnum*minnum)
}


package main

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

func main() {
    var n, min, max int
    var minnum, maxnum uint64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    min = 1e9
    minnum = 0
    max = 0
    maxnum = 0
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    if min == max {
        minnum = minnum / 2
        maxnum = maxnum - minnum
    }

    fmt.Println(max-min, maxnum*minnum)
}


package main

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

func main() {
    var n, min, max int
    var minnum, maxnum uint64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    min = 1e9
    minnum = 0
    max = 0
    maxnum = 0
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    fmt.Println(max-min, maxnum*minnum)
}


package main

import (
    "fmt"
    )

func main() {
    var n, min, minnum, max, maxnum int
    fmt.Scan(&n)

    min = 1e9
    minnum = 0
    max = 0
    maxnum = 0
    for i := 0; i < n; i++ {
        var a int
        fmt.Scan(&a)
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    fmt.Println(max-min, maxnum*minnum)
}


package main

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

func main() {
    var n, min, max, i, a int64
    var minnum, maxnum, count int64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    min = 1e9 + 1
    minnum = 0
    max = 0
    maxnum = 0
    for i = 0; i < n; i++ {
        bs.Scan()
        a, _ = strconv.ParseInt(bs.Text(), 10, 64)
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    count = maxnum*minnum
    if min == max {
        count = n * (n-1) / 2
    }
    fmt.Println(max-min, count)
}


package main

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

func main() {
    var n, i int
    var sum, a, minodd int64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    minodd = 1e9
    for i = 0; i < n; i++ {
        bs.Scan()
        a, _ = strconv.ParseInt(bs.Text(), 10, 64)
        if a % 2 == 0 {
            sum += a
        } else {
            if minodd > a {
                if minodd != 1e9 {
                    sum += minodd
                }
                minodd = a
            } else {
                sum += a
            }
        }
    }

    if sum % 2 != 0 {
        sum += minodd
    }

    fmt.Println(sum)
}


package main

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

func main() {
    var n, min, max int
    var minnum, maxnum uint64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    min = 1e9 + 1
    minnum = 0
    max = 0
    maxnum = 0
    for i := 0; i < n; i++ {
        bs.Scan()
        a, _ := strconv.Atoi(bs.Text())
        if a == min {
            minnum++
        } else if a < min {
            min = a
            minnum = 1
        }

        if a == max {
            maxnum++
        } else if a > max {
            max = a
            maxnum = 1
        }
    }

    if min == max {
        minnum = minnum / 2
        maxnum = maxnum - minnum
    }

    fmt.Println(max-min, maxnum*minnum)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]

	if big == small {
		fmt.Println(0, n*(n-1)/2)
	}

	var bigCount, smallCount int64

	for i := 0; i < len(array); i++ {
		if array[i] == big {
			bigCount++
		}
		if array[i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int64
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < int(n); i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]

	if big == small {
		fmt.Println(0, n*(n-1)/2)
		return
	}

	var bigCount, smallCount int64

	for i := 0; i < len(array); i++ {
		if array[i] == big {
			bigCount++
		}
		if array[i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]

	if big == small {
		fmt.Println(0, n*(n-1)/2)
		return
	}

	var bigCount, smallCount int64

	for i := 0; i < len(array); i++ {
		if array[i] == big {
			bigCount++
		}
		if array[i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]
	bigCount := 1
	smallCount := 1
	for i := 1; i <= len(array)/2; i++ {
		if array[i] == big {
			bigCount++
		}
		if array[len(array)-i-1] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	count := 1
	for i := 1; i <= len(array)/2; i++ {
		if array[i]-array[len(array)-i] == less {
			count++
		}
	}
	fmt.Println(less, count*count)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]
	bigCount := 1
	smallCount := 1
	for i := 1; i <= len(array)/2; i++ {
		if array[i] == big {
			bigCount++
		}
		if array[len(array)-i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	if bigCount < smallCount {
		smallCount = bigCount
	}

	if smallCount < bigCount {
		bigCount = smallCount
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]

	if big == small {
		fmt.Println(0, len(array))
	}

	bigCount := 0
	smallCount := 0

	for i := 0; i < len(array); i++ {
		if array[i] == big {
			bigCount++
		}
		if array[i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] >= array[j]
	})

	less := array[0] - array[len(array)-1]
	count := 1
	for i := 1; i <= len(array)/2; i++ {
		if array[i]-array[len(array)-i] == less {
			count++
		}
	}
	fmt.Println(less, count*count)
}


package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	if n == 1 {
		fmt.Println(0, 0)
	}

	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &array[i])
	}

	sort.Slice(array, func(i, j int) bool {
		return array[i] > array[j]
	})

	less := array[0] - array[len(array)-1]
	big := array[0]
	small := array[len(array)-1]
	bigCount := 1
	smallCount := 0
	for i := 1; i < len(array); i++ {
		if array[i] == big {
			bigCount++
		}
		if array[i] == small {
			smallCount++
		}
		//fmt.Println("testzhaoyi ", array[i], array[len(array)-i], bigCount, smallCount)
	}

	fmt.Println(less, bigCount*smallCount)
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	var x int
	tmap := make(map[int]int)
	for i := 0; i < n; i++ {
		x = readInt()
		tmap[x] = tmap[x] + 1
	}

	type mapii struct {
		k int
		v int
	}
	var bmap []mapii

	for k, v := range tmap {
		bmap = append(bmap, mapii{k, v})
	}

	sort.Slice(bmap, func(i, j int) bool {
		return bmap[i].k < bmap[j].k
	})

	if len(bmap) != 0 {
		fmt.Println(bmap[len(bmap)-1].k - bmap[0].k, int64(bmap[len(bmap)-1].v) * int64(bmap[0].v))
	} else {
		fmt.Println(0, 1)
	}
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	var x int
	tmap := make(map[int]int)
	for i := 0; i < n; i++ {
		x = readInt()
		tmap[x] = tmap[x] + 1
	}

	type mapii struct {
		k int
		v int
	}
	var bmap []mapii

	for k, v := range tmap {
		bmap = append(bmap, mapii{k, v})
	}

	sort.Slice(bmap, func(i, j int) bool {
		return bmap[i].k < bmap[j].k
	})

	if len(bmap) != 0 {
		fmt.Println(bmap[len(bmap)-1].k - bmap[0].k, int64(bmap[len(bmap)-1].v) * int64(bmap[0].v))
	} else {
		fmt.Println(0, 0)
	}
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	var x int
	tmap := make(map[int]int)
	for i := 0; i < n; i++ {
		x = readInt()
		tmap[x] = tmap[x] + 1
	}

	type mapii struct {
		k int
		v int
	}
	var bmap []mapii

	for k, v := range tmap {
		bmap = append(bmap, mapii{k, v})
	}

	sort.Slice(bmap, func(i, j int) bool {
		return bmap[i].k < bmap[j].k
	})

	fmt.Println(bmap[len(bmap)-1].k - bmap[0].k, bmap[len(bmap)-1].v * bmap[0].v)
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	var x int
	tmap := make(map[int]int)
	for i := 0; i < n; i++ {
		x = readInt()
		tmap[x] = tmap[x] + 1
	}

	type mapii struct {
		k int
		v int
	}
	var bmap []mapii

	for k, v := range tmap {
		bmap = append(bmap, mapii{k, v})
	}

	sort.Slice(bmap, func(i, j int) bool {
		return bmap[i].k < bmap[j].k
	})

	fmt.Println(bmap[len(bmap)-1].k - bmap[0].k, int64(bmap[len(bmap)-1].v) * int64(bmap[0].v))
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := readInt()
	var x int
	tmap := make(map[int]int)
	for i := 0; i < n; i++ {
		x = readInt()
		tmap[x] = tmap[x] + 1
	}

	type mapii struct {
		k int
		v int
	}
	var bmap []mapii

	for k, v := range tmap {
		bmap = append(bmap, mapii{k, v})
	}

	sort.Slice(bmap, func(i, j int) bool {
		return bmap[i].k < bmap[j].k
	})

	if len(bmap) != 1 {
		fmt.Println(bmap[len(bmap)-1].k - bmap[0].k, int64(bmap[len(bmap)-1].v) * int64(bmap[0].v))
	} else {
		fmt.Println(0, (int64(bmap[0].v) * int64(bmap[0].v-1))/2)
	}
}


<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = count(array_keys($beauty, max($beauty)));
    $min_position = count(array_keys($beauty, min($beauty)));

    if($diff_max_beauty==0){
        $count = factorial($maxposition)/(factorial(2)*factorial($maxposition-2));
    }
 else {
        $count = $maxposition*$min_position;
    }
    echo $diff_max_beauty." ". $count;

}

function factorial($number) {

    if ($number < 2) {
        return 1;
    } else {
        return ($number * factorial($number-1));
    }
}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);


<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = array_keys($beauty, max($beauty));
    $min_position = array_keys($beauty, min($beauty));

    $count = count($min_position)*  count($maxposition);
    if($count==0)
        $count=1;
    echo $diff_max_beauty." ". $count;

}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);


<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = count(array_keys($beauty, max($beauty)));
    $min_position = count(array_keys($beauty, min($beauty)));

    if($diff_max_beauty==0){
        $count = $maxposition*($maxposition-1)/2;
    }
 else {
        $count = $maxposition*$min_position;
    }
    echo $diff_max_beauty." ". $count;

}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);


<?php
// 459B     Пашмак и цветы
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

sort($arr);

$max = $arr[$n-1] - $arr[0];

$colfirst = $colend = 1;
for ($i=1; $i < $n; $i++) {
    if ($arr[$i] === $arr[0]) {
        $colfirst ++;
    } else {
        break;
    }
}

for ($i=$n-2; $i >= 0; $i--) {
    if ($arr[$i] === $arr[$n-1]) {
        $colend ++;
    } else {
        break;
    }
}

if ($i < 0) {
    $sum = 0;
    for ($j=1; $j < $n; $j++) {
        $sum += $j;
    }
    $col = $n * ($n - 1) - $sum;
} else {
    $col = $colfirst * $colend;
}

echo "$max $col";

?>


<?php
// 459B     Пашмак и цветы
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

sort($arr);

$max = $arr[$n-1] - $arr[0];

$colfirst = $colend = 1;
for ($i=1; $i < $n; $i++) {
    if ($arr[$i] === $arr[0]) {
        $colfirst ++;
    } else {
        break;
    }
}

for ($i=$n-2; $i > 0; $i--) {
    if ($arr[$i] === $arr[$n-1]) {
        $colend ++;
    } else {
        break;
    }
}

$col = $colfirst * $colend;

echo "$max $col";

?>


<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
if($mx != $mn)echo ($mx-$mn)." ".($cmx*$cmn);
else echo ($mx-$mn)." ".(($n*($n-1))/2);
?>


<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
echo ($mx-$mn)." ".($cmx*$cmn);
?>


<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
if($mx != $mn)echo ($mx-$mn)." ".($cmx*$cmn);
else echo ($mx-$mn)." ".($n*($n-1));
?>


<?php
	$n = trim(fgets(STDIN));
	$b = explode(' ', trim(fgets(STDIN)));
	$mx = max($b);
	$mn = min($b);
	$cmx = $cmn = 0;
	foreach($b as $v)
	{
		$cmx += ($v == $mx);
		$cmn += ($v == $mn);
	}
	echo $mx-$mn.' '.($mx == $mn ? floor($n*($n-1)/2) : $cmx*$cmn);
?>


import bisect

def ni():
    return int(raw_input())

def nis():
    return map(int, raw_input().split())

def si():
    return raw_input()

n = ni()
a = nis()

min_val = min(a)
max_val = max(a)

total = 0
if min_val == max_val:
    min_count = a.count(min_val)
    total = min_count * (min_count - 1) / 2
    pass
else:
    min_count = a.count(min_val)
    max_count = a.count(max_val)

    total = min_count * max_count

print max_val - min_val, total


import bisect

def ni():
    return int(raw_input())

def nis():
    return map(int, raw_input().split())

def si():
    return raw_input()

n = ni()
a = nis()

min_val = min(a)
max_val = max(a)

min_count = a.count(min_val)
max_count = a.count(max_val)

print max_val - min_val, min_count * max_count


from collections import Counter
raw_input()
s = map(int,raw_input().split(" "))
if len(set(s)) == 1:
   n = len(s)
   print 0, n*(n-1)/2
   exit(0)
c = Counter(s)
md = max(s) - min(s)
cc = 0
for i in s:
   cc += c[i + md]
print md, cc


from collections import Counter
raw_input()
s = map(int,raw_input().split(" "))
if len(set(s)) == 1:
   print 0, n*(n-1)/2
   exit(0)
c = Counter(s)
md = max(s) - min(s)
cc = 0
for i in s:
   cc += c[i + md]
print md, cc


n=int(raw_input())
N=map(int,raw_input().split())
if max(N)==min(N):
	print max(N)-min(N),n*(n-1)
else:
	print max(N)-min(N),N.count(max(N))*N.count(min(N))


n=int(raw_input())
N=map(int,raw_input().split())
N.sort()
print N[n-1]-N[0],N.count(N[0])*N.count(N[n-1])


n=int(raw_input())
N=map(int,raw_input().split())
if max(N)==min(N):
	print max(N)-min(N),n*(n-1)/2
else:
	print max(N)-min(N),N.count(max(N))*N.count(min(N))


n=int(raw_input())
N=map(int,raw_input().split())
if max(N)==min(N):
	print max(N)-min(N),1
else:
	print max(N)-min(N),N.count(max(N))*N.count(min(N))


from sys import stdin
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    mx, mn = max(a), min(a)
    if mx == mn:
        print 0, n*(n-1)/2
    else:
        print mx - mn, a.count(mx) * a.count(mn)
main()


N = int(input())
a = map(int, raw_input().split())
mx, mn = max(a), min(a)
mxcnt, mncnt = a.count(mx), a.count(mn)
print mx-mn, mxcnt*mncnt


from sys import stdin
def main():
    n = int(input())
    a = map(int, raw_input().split())
    mx, mn = max(a), min(a)
    if mx == mn:
        print 0, n*(n-1)/2
    else:
        print mx - mn, a.count(mx) * a.count(mn)
main()


N = int(input())
a = map(int, raw_input().split())
mx, mn = max(a), min(a)
mxcnt, mncnt = a.count(mx), a.count(mn)
if mx == mn: mxcnt = 1
print mx-mn, mxcnt*mncnt


N = int(input())
a = map(int, raw_input().split())
mx, mn = max(a), min(a)
mxcnt, mncnt = a.count(mx), a.count(mn)
if mx == mn: mxcnt = mncnt = 1
print mx-mn, mxcnt*mncnt


N = int(input())
a = map(int, raw_input().split())
mx, mn = max(a), min(a)
mxcnt, mncnt = a.count(mx), a.count(mn)
if mx == mn: if mxcnt == 2: mxcnt = mncnt = 1
print mx-mn, mxcnt*mncnt


N = int(input())
a = map(int, raw_input().split())
mx, mn = max(a), min(a)
mxcnt, mncnt = a.count(mx), a.count(mn)
if mx == mn:
    if mxcnt == 2:
        mxcnt, mncnt = 1, 1
    else:
        mncnt = 1
print mx-mn, mxcnt*mncnt


n = raw_input()
flowers = map(int, raw_input().split())

flowers.sort()

# least = min(flowers)
# most = max(flowers)
maxGap = flowers[-1] - flowers[0]

cached = {}

for i in flowers:
	if i not in cached:
		cached[i] = 1
	else:
		cached[i] += 1

result = 0
# print(cached)
for i in flowers:
	diff = i - maxGap
	if diff in cached:
		if diff == i:
			# print(cached[i])
			result += (cached[i] * (cached[i]-1)) / 2
		else:
			result += cached[i] * cached[diff]
		cached[i] = 0
		cached[diff] = 0

print maxGap, result


n = raw_input()
flowers = map(int, raw_input().split())

flowers.sort()

# least = min(flowers)
# most = max(flowers)
maxGap = flowers[-1] - flowers[0]

cached = {}

for i in flowers:
	if i not in cached:
		cached[i] = 1
	else:
		cached[i] += 1

result = 0

for i in flowers:
	diff = i - maxGap
	if diff in cached:
		if diff == i:
			result += cached[i] / 2
		else:
			result += cached[i] * cached[diff]
		cached[i] = 0
		cached[diff] = 0

print maxGap, result


n = raw_input()
flowers = map(int, raw_input().split())

high = max(flowers)
low = max(flowers)

if high == low:
	print 0, (flowers.count(high) * flowers.count(high) - 1) / 2
else:
	print high-low, flowers.count(high) * flowers.count(low)


n = raw_input()
flowers = map(int, raw_input().split())

least = min(flowers)
most = max(flowers)
maxGap = most-least

cached = {}

for i in flowers:
	if i not in cached:
		cached[i] = 1
	else:
		cached[i] += 1

result = 0

for i in flowers:
	diff = i - maxGap
	if diff in cached:
		if diff == i:
			result += cached[i] / 2
		else:
			result += cached[i] * cached[diff]
		cached[i] = 0
		cached[diff] = 0

print maxGap, result


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e18+100;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (mid > w / (b * f)) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = r / (b * f);

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            ll j = (l-1) / (b * f);

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << "\n";
    }
}


#pragma GCC optimize("03")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll count = 0;

            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
            }

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                if (i == 0) --m;
                count += m;
            }
            ll L = count;

            cout << (r - l + 1 ) - (R - L) + 1 << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e12;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (b * f * mid > w) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            //cout << "largest i: " << i << endl;

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += (i - 1) * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            //cout << "to R: " << R << endl;

            ll j = largest_i(b, f, l - 1);

            //cout << "largest j: " << j << endl;

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = (j - 1) * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            //cout << "to L: " << L << endl;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            /*ll left = 0;
            ll right = 1e18;

            while (left < right) {
                ll mid = left + (right - left) / 2;

                if (b * f * mid > r) right = mid;
                else left = mid + 1;
            }
            --left;

            ll R = 0;

            if (left != 0) R += (left - 1) * b;

            ll m = b;
            if (left + b > r) m = r + 1 - (b * f * left);

            R += m;

            left = 0;
            right = 1e18;

            --l;

            while (left < right) {
                ll mid = left + (right - left) / 2;

                if (b * f * mid > l) right = mid;
                else left = mid + 1;
            }
            --left;

            cout << "largest i: " << left << endl;

            ll L = 0;

            if (left != 0) L = (left - 1) * b;

            m = b;
            if (left + b > r) m = l + 1 - (b * f * left);

            L += m;

            if (left == 0) --L;

            cout << "to L: " << L << endl;*/

            ll count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
            }

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                //if (i == 0) --m;
                count += m;
            }
            ll L = count;

            //cout << "to R is : " << R << endl;
            //cout << "to L is : " << L << endl;

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll count = 0;
            ll f = min(a/gcd(a, b), b/gcd(a,b));
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b >= r) m = r + 1 - p;
                count += m;
            }

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b >= l - 1) m = l - p;
                if (i == 0) --m;
                count += m;
            }
            ll L = count;

            cout << (r - l + 1 ) - (R - L) + 1 << " ";
        }
        cout << endl;
        /*
        int count = 0;
        for (int x = 1; x < 4; ++x) {
            if ((x%a)%b == (x%b)%a) {
                ++count;
            }
        }

        cout << "true: " << count << endl;

        count = 0;
        int p = 0;
        for (int i = 0; i < 1000; ++i) {
            p = ((b) * min(a/gcd(a, b), b/gcd(a,b)) * i);
            int m = b;
            if (p > 3) break;
            if (p + b >= 3) m = 3 + 1 - p;
            if (i == 0) --m;
            count += m;
            cout << m << endl;
        }
        cout << "try: " << count << endl;*/
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e18;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (mid > w / (b * f)) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            //cout << "largest i: " << i << endl;

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            //cout << "to R: " << R << endl;

            ll j = largest_i(b, f, l - 1);

            //cout << "largest j: " << j << endl;

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            //cout << "to L: " << L << endl;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = r / (b * f);

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += r + 1 - p;

            ll j = (l-1) / (b * f);

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e18+100;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (mid > w / (b * f)) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            ll j = largest_i(b, f, l - 1);

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e12;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (b * f * mid > w) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            //cout << "largest i: " << i << endl;

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            //cout << "to R: " << R << endl;

            ll j = largest_i(b, f, l - 1);

            //cout << "largest j: " << j << endl;

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            //cout << "to L: " << L << endl;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e18+100;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (mid > w / (b * f)) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            ll j = largest_i(b, f, l - 1);

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = r / (b * f);

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            ll j = (l-1) / (b * f);

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;
            /*
            ll count = 0;
            ll f = min(a/gcd(a, b), b/gcd(a,b));
            for (int i = 0; i < 10e7; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b >= r) m = r + 1 - p;
                if (i == 0) --m;
                count += m;
            }

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e7; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b >= l - 1) m = l - p;
                if (i == 0) --m;
                count += m;
            }
            ll L = count;*/

            int count = 0;
            for (int x = 1; x <= r; ++x) {
                if ((x%a)%b == (x%b)%a) {
                    ++count;
                }
            }

            int R = count;

            count = 0;
            for (int x = 1; x < l; ++x) {
                if ((x%a)%b == (x%b)%a) {
                    ++count;
                }
            }

            int L = count;

            cout << (r - l + 1 ) - (R - L) << endl;
        }
        /*
        int count = 0;
        for (int x = 1; x < 4; ++x) {
            if ((x%a)%b == (x%b)%a) {
                ++count;
            }
        }

        cout << "true: " << count << endl;

        count = 0;
        int p = 0;
        for (int i = 0; i < 1000; ++i) {
            p = ((b) * min(a/gcd(a, b), b/gcd(a,b)) * i);
            int m = b;
            if (p > 3) break;
            if (p + b >= 3) m = 3 + 1 - p;
            if (i == 0) --m;
            count += m;
            cout << m << endl;
        }
        cout << "try: " << count << endl;*/
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e17;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (b * f * mid > w) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            //cout << "largest i: " << i << endl;

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += (i - 1) * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            //cout << "to R: " << R << endl;

            ll j = largest_i(b, f, l - 1);

            //cout << "largest j: " << j << endl;

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = (j - 1) * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            //cout << "to L: " << L << endl;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll largest_i(int b, ll f, ll w) {
    ll left = 0;
    ll right = 1e13;

    while (left < right) {
        ll mid = left + (right - left) / 2;
        if (b * f * mid > w) right = mid;
        else left = mid + 1;
    }
    return left - 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        ll f = min(a/gcd(a, b), b/gcd(a,b));

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll p = 0;

            ll i = largest_i(b, f, r);

            //cout << "largest i: " << i << endl;

            p = b * f * i;

            ll R = 0;

            if (i != 0) R += i * b;

            ll m = b;
            if (p + b > r) m = r + 1 - p;

            R += m;

            //cout << "to R: " << R << endl;

            ll j = largest_i(b, f, l - 1);

            //cout << "largest j: " << j << endl;

            p = b * f * j;

            ll L = 0;

            if (j != 0) L = j * b;

            m = b;
            if (p + b > l - 1) m = l - p;

            L += m;

            //cout << "to L: " << L << endl;

            /*
            ll count = 0;
            int j = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b > r) m = r + 1 - p;
                count += m;
                j = i;
            }

            cout << "largest i: " << j << endl;

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e9L; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b > l - 1) m = l - p;
                count += m;
                j = i;
            }

            cout << "largest j: " << j << endl;
            ll L = count;

            cout << "to R is : " << R << endl;
            cout << "to L is : " << L << endl;*/

            cout << (r - l + 1 ) - (R - L) << " ";
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T; cin >> T;
    for (int t = 0; t < T; ++t) {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        int Q; cin >> Q;

        for (int q = 0; q < Q; ++q) {
            ll l, r; cin >> l >> r;

            ll count = 0;
            ll f = min(a/gcd(a, b), b/gcd(a,b));
            for (int i = 0; i < 10e7; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > r) break;
                if (p + b >= r) m = r + 1 - p;
                count += m;
            }

            ll R = count;

            count = 0;
            for (int i = 0; i < 10e7; ++i) {
                ll p = b * f * i;
                ll m = b;
                if (p > l - 1) break;
                if (p + b >= l - 1) m = l - p;
                if (i == 0) --m;
                count += m;
            }
            ll L = count;

            cout << (r - l + 1 ) - (R - L) + 1 << " ";
        }
        cout << endl;
        /*
        int count = 0;
        for (int x = 1; x < 4; ++x) {
            if ((x%a)%b == (x%b)%a) {
                ++count;
            }
        }

        cout << "true: " << count << endl;

        count = 0;
        int p = 0;
        for (int i = 0; i < 1000; ++i) {
            p = ((b) * min(a/gcd(a, b), b/gcd(a,b)) * i);
            int m = b;
            if (p > 3) break;
            if (p + b >= 3) m = 3 + 1 - p;
            if (i == 0) --m;
            count += m;
            cout << m << endl;
        }
        cout << "try: " << count << endl;*/
    }
}


#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0,sum1=0,pra=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
            else
            {
                ll LCM = std::lcm(a,b) ;
                if(l>val)
                {
                    ans = l/LCM;
                    ans1 = l%LCM;
                    if(ans1>val)
                     ans1=ans1-val;

                     sum1 = ans*LCM - ans*val + ans1 + 1;
                }
                ans=r/LCM;
                ans1=r%LCM;
                if(ans1>val)
                ans1=ans1-val;

                sum=ans*LCM - ans*val + ans1 + 1;

                if(sum1!=0)
                cout<<sum-sum1 + 1<<" ";
                else
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0,sum1=0,pra=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
            else
            {
                ll LCM = std::lcm(a,b) ;
                if(l>val)
                {
                    ans = l/LCM;
                    ans1 = l%LCM;
                    if(ans1>=val)
                     ans1=ans1-val;
                     else
                     ans1=-1;

                     sum1 = ans*LCM - ans*val + ans1 + 1;
                     ans=0;ans1=0;
                }
                ans=r/LCM;
                ans1=r%LCM;
                if(ans1>=val)
                ans1=ans1-val;
                else
                ans=-1;

                sum=ans*LCM - ans*val + ans1 + 1;

                if(sum1!=0)
                cout<<sum-sum1 + 1<<" ";
                else
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
            else
            {
                ans=(l-val)/val;
                ans1=l%val;
                //cout<<ans<<ans1<<endl;
                 sum=ans1+1+(ans)*val;
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0,sum1=0,pra=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
            else
            {
                ll LCM = std::lcm(a,b) ;
                if(l>val)
                {
                    ans = l/LCM;
                    ans1 = l%LCM;
                    if(ans1>=val)
                     ans1=ans1-val;
                     else
                     ans1=-1;

                     sum1 = ans*LCM - ans*val + ans1 + 1;
                     ans=0;ans1=0;
                }
                ans=r/LCM;
                ans1=r%LCM;
                if(ans1>=val)
                ans1=ans1-val;
                else
                ans=-1;

                sum=ans*LCM - ans*val + ans1 + 1;

                if(sum1>0&&sum1<sum)
                cout<<sum-sum1 + 1<<" ";
                else
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        ll LCM = std::lcm(a,b) ;
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0,sum1=0,pra=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
             else if(val==LCM)
            cout<<0<<" ";
            else
            {

                if(l>val)
                {
                    ans = l/LCM;
                    ans1 = l%LCM;
                    if(ans1>=val)
                     ans1=ans1-val;
                     else
                     ans1=-1;

                     sum1 = ans*LCM - ans*val + ans1 + 1;
                     ans=0;ans1=0;
                }
                ans=r/LCM;
                ans1=r%LCM;
                if(ans1>=val)
                ans1=ans1-val;
                else
                ans1=-1;

                sum=ans*LCM - ans*val + ans1 + 1;

                if(sum1>0&&sum1<=sum)
                {
                    if(((l%a)%b)!=((l%b)%a))
                     cout<<sum-sum1 +1<<endl;
                     else
                     cout<<sum-sum1<<endl;
                }
                else
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0,sum1=0,pra=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
             else if(val==LCM)
            cout<<0<<" ";
            else
            {
                ll LCM = std::lcm(a,b) ;
                if(l>val)
                {
                    ans = l/LCM;
                    ans1 = l%LCM;
                    if(ans1>=val)
                     ans1=ans1-val;
                     else
                     ans1=-1;

                     sum1 = ans*LCM - ans*val + ans1 + 1;
                     ans=0;ans1=0;
                }
                ans=r/LCM;
                ans1=r%LCM;
                if(ans1>=val)
                ans1=ans1-val;
                else
                ans1=-1;

                sum=ans*LCM - ans*val + ans1 + 1;

                if(sum1>0&&sum1<=sum)
                cout<<sum-sum1 + 1<<" ";
                else
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>

int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,q,i;
        cin>>a>>b>>q;
        ll l ,r;
       ll val=max(a,b);
        for(i=0;i<q;i++)
        {ll ans=0,ans1=0,sum=0;
        cin>>l>>r;
            if(r<val)
            cout<<0<<" ";
            else
            {
                if(l>val)
                sum=sum-l;

                ans=(r-val)/val;
                ans1=r%val;
               // cout<<ans<<" "<<ans1<<endl;
                 sum=sum+ans1+1+(ans)*val;
                cout<<sum<<" ";
            }
        }
        cout<<endl;
    }
}