As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of ai cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest and the lowest of the towers. For example, if Petya built five cube towers with heights (8, 3, 2, 6, 3), the instability of this set is equal to 6 (the highest tower has height 8, the lowest one has height 2). The boy wants the instability of his set of towers to be as low as possible. All he can do is to perform the following operation several times: take the top cube from some tower and put it on top of some other tower of his set. Please note that Petya would never put the cube on the same tower from which it was removed because he thinks it's a waste of time. Before going to school, the boy will have time to perform no more than k such operations. Petya does not want to be late for class, so you have to help him accomplish this task.

The first line contains two space-separated positive integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000) — the number of towers in the given set and the maximum number of operations Petya can perform. The second line contains n space-separated positive integers ai (1 ≤ ai ≤ 104) — the towers' initial heights.

In the first line print two space-separated non-negative integers s and m (m ≤ k). The first number is the value of the minimum possible instability that can be obtained after performing at most k operations, the second number is the number of operations needed for that. In the next m lines print the description of each operation as two positive integers i and j, each of them lies within limits from 1 to n. They represent that Petya took the top cube from the i-th tower and put in on the j-th one (i ≠ j). Note that in the process of performing operations the heights of some towers can become equal to zero. If there are multiple correct sequences at which the minimum possible instability is achieved, you are allowed to print any of them.

NoteIn the first sample you need to move the cubes two times, from the second tower to the third one and from the second one to the first one. Then the heights of the towers are all the same and equal to 6.

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	a := make([]int, n)

	if n == 1 {
		println(0, 0)
		return
	}

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	max, min := pos(a)
	m := 0
	move := make([]byte, 0, 10)

	if a[max] - a[min] > 1 {
		for ; k > 0; k-- {
			max, min = pos(a)

			if a[max] == a[min] || a[max] - a[min] == 1 {
				break
			}
			// println(a[max]-a[min], m)
			// println(a)

			a[max]--
			a[min]++
			m++
			move = append(move, fmt.Sprintln(max+1, min+1)...)
			// println()
		}
	}

	max, min = pos(a)

	// println()
	println(a[max] - a[min], m)
	println(string(move))
}

func pos(a []int) (int, int) {
	max, min := 0, 0

	for i := 1; i < len(a); i++ {
		if a[i] > a[max] {
			max = i
		}

		if a[i] < a[min] {
			min = i
		}
	}

	return max, min
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import "fmt"

func main() {
    var ans, i, j, n, m, mi, mx int
    var a[1001] int
    var f[1001] int
    var r[1001] int

    fmt.Scan( &n, &m )
    for i = 1; i <= n; i++ {
        fmt.Scan( &a[i] )
    }
    ans = 0
    for i = 1; i <= m; i++ {
        mx = 1
        mi = 1
        for j := 2; j <= n; j++ {
            if( a[j] > a[mx] ) {
                mx = j
            }
            if( a[j] < a[mi] ) {
                mi = j
            }
        }
        if( a[mx] - a[mi] > 1 ) {
            f[i] = mx
            r[i] = mi
            a[mx]--
            a[mi]++
            ans++
        } else {
            break
        }
    }
    mx = 1
    mi = 1
    for j = 2; j <= n; j++ {
        if( a[j] > a[mx] ) {
            mx = j
        }
        if( a[j] < a[mi] ) {
            mi = j
        }
    }
    fmt.Printf( "%d %d\n", a[mx] - a[mi], ans )
    for i := ans; i > 0; i-- {
        fmt.Printf( "%d %d\n", f[i], r[i] )
    }
}

package main

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

type Pair struct {
	a int
	b int
}

type Vector struct {
	items []Pair
}

func (v Vector) Len() int {
	return len(v.items)
}

func (v Vector) Less(i, j int) bool {
	return v.items[i].a < v.items[j].a
}

func (v Vector) Swap(i, j int) {
	var t = v.items[i]
	v.items[i] = v.items[j]
	v.items[j] = t
}

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

func echo(v *Vector) {
	for i := 0; i < v.Len(); i++ {
		fmt.Printf("%d ", v.items[i])
	}
	fmt.Println()
}

func solve(a []Pair, k int) {
	var v = Vector{a}
	var backup = append([]Pair(nil), a...)

	var n = v.Len()
	if n == 1 {
		fmt.Printf("0 0\n")
		return
	}

	sort.Sort(v)
	var best = v.items[n-1].a - v.items[0].a
	for i := 0; i < k; i++ {
		v.items[n-1].a--
		v.items[0].a++
		sort.Sort(v)
		best = min(best, v.items[n-1].a-v.items[0].a)
	}

	var steps = make([]Pair, 0)
	v = Vector{backup}
	sort.Sort(v)
	for i := 0; i < k; i++ {
		var diff = v.items[n-1].a - v.items[0].a
		if diff == best {
			break
		}
		steps = append(steps, Pair{v.items[n-1].b, v.items[0].b})
		v.items[n-1].a--
		v.items[0].a++
		sort.Sort(v)
	}

	fmt.Printf("%d %d\n", best, len(steps))
	for _, s := range steps {
		fmt.Printf("%d %d\n", s.a, s.b)
	}
}

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		fmt.Printf("Error reading input: %s", err)
		os.Exit(0)
	}

	var a = make([]Pair, 0, n)
	for i := 0; i < n; i++ {
		var x int
		if _, err := fmt.Scanf("%d", &x); err != nil {
			fmt.Printf("Error: %s", err)
			os.Exit(0)
		}
		a = append(a, Pair{x, i + 1})
	}
	solve(a, k)
}

package main

import (
	"fmt"
)

func diff(a []int) int {
	var h, l int
	for i := 0; i < len(a); i++ {
		if a[i] < a[l] {
			l = i
		}
		if a[i] > a[h] {
			h = i
		}
	}
	return a[h] - a[l]
}

func flattern(a []int, k int) int {
	added := make([]bool, len(a))
	for i := 0; i < k; i++ {
		var h, l int
		for j := 0; j < len(a); j++ {
			if a[j] < a[l] {
				l = j
			}
			if a[j] > a[h] {
				h = j
			}
		}
		added[l] = true
		if added[h] {
			return i
		}
		a[l]++
		a[h]--
	}
	return k
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	copy(b, a)
	m := flattern(b, k)
	s := diff(b)
	fmt.Println(s, m)
	for i := 0; i < m; i++ {
		var h, l int
		for j := 0; j < n; j++ {
			if a[j] < a[l] {
				l = j
			}
			if a[j] > a[h] {
				h = j
			}
		}
		a[h]--
		a[l]++
		fmt.Println(h+1, l+1)
	}
}

package main

import "fmt"

func main() {
    var ans, i, j, n, m, mi, mx int
    var a[1001] int
    var f[1001] int
    var r[1001] int

    fmt.Scan( &n, &m )

    for i = 1; i <= n; i++ {
        fmt.Scan( &a[i] )
    }
    ans = 0
    for i = 1; i <= n; i++ {
        mx = 1
        mi = 1
        for j := 2; j <= n; j++ {
            if( a[j] > a[mx] ) {
                mx = j
            }
            if( a[j] < a[mi] ) {
                mi = j
            }
        }
        if( a[mx] - a[mi] > 1 ) {
            f[i] = mx
            r[i] = mi
            a[mx]--
            a[mi]++
            ans++
        } else {
            break
        }
    }
    mx = 1
    mi = 1
    for j = 2; j <= n; j++ {
        if( a[j] > a[mx] ) {
            mx = j
        }
        if( a[j] < a[mi] ) {
            mi = j
        }
    }
    fmt.Printf( "%d %d\n", a[mx] - a[mi], ans )
    for i := ans; i > 0; i-- {
        fmt.Printf( "%d %d\n", f[i], r[i] )
    }
}

package main

import (
	"fmt"
	"log"
	"os"
	"sort"
)

type Pair struct {
	a int
	b int
}

type Vector struct {
	items []Pair
}

func (v Vector) Len() int {
	return len(v.items)
}

func (v Vector) Less(i, j int) bool {
	return v.items[i].a < v.items[j].a
}

func (v Vector) Swap(i, j int) {
	var t = v.items[i]
	v.items[i] = v.items[j]
	v.items[j] = t
}

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

func echo(v *Vector) {
	for i := 0; i < v.Len(); i++ {
		fmt.Printf("%d ", v.items[i])
	}
	fmt.Println()
}

func solve(a []Pair, k int) {
	var v = Vector{a}
	var backup = append([]Pair(nil), a...)

	var n = v.Len()
	if n == 1 {
		fmt.Printf("0 0\n")
		return
	}

	sort.Sort(v)
	var best = v.items[n-1].a - v.items[0].a
	for i := 0; i < k; i++ {
		v.items[n-1].a--
		v.items[0].a++
		sort.Sort(v)
		best = min(best, v.items[n-1].a-v.items[0].a)
	}

	var steps = make([]Pair, 0)
	v = Vector{backup}
	sort.Sort(v)
	for i := 0; i < k; i++ {
		var diff = v.items[n-1].a - v.items[0].a
		if diff == best {
			break
		}
		steps = append(steps, Pair{v.items[n-1].b, v.items[0].b})
		v.items[n-1].a--
		v.items[0].a++
		sort.Sort(v)
	}

	fmt.Printf("%d %d\n", best, len(steps))
	for _, s := range steps {
		fmt.Printf("%d %d\n", s.a, s.b)
	}
}

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d", &n, &k); err != nil {
		log.Printf("Error reading input: %s", err)
		os.Exit(0)
	}

	var a = make([]Pair, 0, n)
	for i := 0; i < n; i++ {
		var x int
		if _, err := fmt.Scanf("%d", &x); err != nil {
			log.Printf("Error: %s", err)
			os.Exit(0)
		}
		a = append(a, Pair{x, i + 1})
	}
	solve(a, k)
}

package main

import (
	"fmt"
)

func diff(a []int) int {
	var h, l int
	for i := 0; i < len(a); i++ {
		if a[i] < a[l] {
			l = i
		}
		if a[i] > a[h] {
			h = i
		}
	}
	return a[h] - a[l]
}

func flattern(a []int, k int) int {
	added := make([]bool, len(a))
	for i := 0; i < k; i++ {
		var h, l int
		for j := 0; j < len(a); j++ {
			if a[j] < a[l] {
				l = j
			}
			if a[j] > a[h] {
				h = j
			}
		}
		added[l] = true
		if added[h] {
			return i
		}
		a[l]++
		a[h]--
	}
	return k
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	copy(b, a)
	m := flattern(b, k)
	s := diff(b)
	fmt.Println(s, m)
	for i := 0; i < m; i++ {
		var h, l int
		for j := 0; j < n; j++ {
			if a[j] < a[l] {
				l = j
			}
			if a[j] > a[h] {
				h = j
			}
		}
		a[h]--
		a[l]++
		fmt.Println(l+1, h+1)
	}
}


Ridbit starts with an integer $$$n$$$.In one move, he can perform one of the following operations:   divide $$$n$$$ by one of its proper divisors, or  subtract $$$1$$$ from $$$n$$$ if $$$n$$$ is greater than $$$1$$$. A proper divisor is a divisor of a number, excluding itself. For example, $$$1$$$, $$$2$$$, $$$4$$$, $$$5$$$, and $$$10$$$ are proper divisors of $$$20$$$, but $$$20$$$ itself is not.What is the minimum number of moves Ridbit is required to make to reduce $$$n$$$ to $$$1$$$?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

For each test case, output the minimum number of moves required to reduce $$$n$$$ to $$$1$$$.

NoteFor the test cases in the example, $$$n$$$ may be reduced to $$$1$$$ using the following operations in sequence$$$1$$$$$$2 \xrightarrow{} 1$$$$$$3 \xrightarrow{} 2 \xrightarrow{} 1$$$$$$4 \xrightarrow{} 2 \xrightarrow{} 1$$$$$$6 \xrightarrow{} 2 \xrightarrow{} 1$$$$$$9 \xrightarrow{} 3 \xrightarrow{} 2\xrightarrow{} 1$$$

package main

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

// var reader *bufio.Reader = bufio.NewReader(os.Stdin)
// var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
// func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numCases, _ := strconv.Atoi(scanner.Text())
	for numCases > 0 {
		// calculate all divisors
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		if x == 1 {
			fmt.Println(0)
		} else if x == 2 {
			fmt.Println(1)
		} else if x == 3 {
			fmt.Println(2)
		} else if x%2 == 0 {
			fmt.Println(2)
		} else {
			fmt.Println(3)
		}

		numCases--

	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for tc := 1; tc <= t; tc++ {
		var n int
		fmt.Scan(&n)
		if n <= 3 {
			fmt.Println(n - 1)
		} else {
			if (n-3)%2 == 0 {
				fmt.Println(3)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	var n []int64
	for t != 0 {
		var j int64
		fmt.Scanln(&j)
		n = append(n, j)
		t--
	}
	for _, k := range n {
		compute(k, 0)
	}
}

func compute(n, steps int64) {
	if n == 1 {
		fmt.Printf("%d\n", steps)
	} else {
		steps++
		n = action(n)
		compute(n, steps)
	}
}
func action(n int64) int64 {
	if n == 2 || n%2 != 0 {
		return n - 1
	}
	return 2
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	var n []int64
	for t != 0 {
		var j int64
		fmt.Scanln(&j)
		n = append(n, j)
		t--
	}
	for _, k := range n {
		compute(k, 0)
	}
}

func compute(n, steps int64) {
	if n == 1 {
		fmt.Printf("%d\n", steps)
	} else {
		steps++
		s := smallestFactor(n)
		if s == n {
			n--
		} else {
			n = s
		}
		compute(n, steps)
	}
}
func smallestFactor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	return n - 1
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func solveA() {
	var n int
	scanf("%d\n", &n)
	ans := 0
	if n % 2 == 0 {
		if n >= 4 {
			ans = 2
		} else if n == 2 {
			ans = 1
		}
	} else {
		if n >= 5 {
			ans = 3
		} else if n == 3 {
			ans = 2
		}
	}
	printf("%d\n", ans)
}

type point struct {
	left int
	right int
}

func solveB() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	var s string
	scanf("%s\n", &s)
	var P0, P1 point = point{n, -1}, point{n, -1}
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			P0.right = i
		} else {
			P1.right = i
		}
	}

	for i := n - 1; i >= 0; i-- {
		if s[i] == '0' {
			P0.left = i
		} else {
			P1.left = i
		}
	}

	for ; q > 0; q-- {
		var l, r int
		scanf("%d %d\n", &l, &r)
		l--
		r--
		ans := "NO"
		if (s[l] == '0' && P0.left < l || s[l] == '1' && P1.left < l) ||
			(s[r] == '0' && P0.right > r || s[r] == '1' && P1.right > r) {
			ans = "YES"
		}

		printf("%s\n", ans)
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveA()
	}
}

package main
import (
	"os"
	"fmt"
	"bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
	q := 0
	fmt.Fscan(rd, &q)
	for tc := 0; tc < q; tc++ {
		n := 0
		fmt.Fscan(rd, &n)
		if n <= 3 {
			fmt.Println(n - 1)
		} else {
			fmt.Println(2 + n % 2)
		}
	}
}

package main

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

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

func scanf(f string, a... interface{}) {
	fmt.Fscanf(reader, f, a...)
}

func printf(f string, a... interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func main() {

	var T, i, n, temp uint32
	out := []uint32{}

	scanf("%d \n", &T)

	for i=0; i<T; i++ {
		scanf("%d \n", &n)
		temp = 0
		for ;n > 1; {
			if n == 2 {
				n = n / 2
				temp++
				continue
			}
			if n % 2 == 0 {
				n = n / (n / 2)
				temp++
			}else {
				n = n - 1
				temp++
			}

		}
		out = append(out, temp)
	}

	for i=0; i<T; i++ {
		fmt.Println(out[i])
	}

}

package main

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

// var reader *bufio.Reader = bufio.NewReader(os.Stdin)
// var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
// func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func divisor(n int) int {
	for i := 3; i*i <= n; i = i + 2 {
		if n%i == 0 {
			return i
		}

	}
	return n
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numCases, _ := strconv.Atoi(scanner.Text())
	for numCases > 0 {
		// calculate all divisors
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		solution := 0
		for x > 1 {
			//fmt.Println("Current start: ", x)
			if x == 2 {
				solution = solution + 1
				break
			}
			if x == 3 {
				solution = solution + 2
				break
			}
			if x%2 == 0 {
				solution = solution + 1
				x = 2
				continue
			} else {
				//check for perfect squares
				test := math.Sqrt(float64(x))
				f := math.Floor(test)
				if x-int(f) == 0 {
					//found a match
					solution = solution + 1
					x = int(test)
				} else {
					choice := divisor(x)
					if choice == x {
						x = x - 1
						solution = solution + 1
						//fmt.Println("Choice == x")
						//	fmt.Println(x)
					} else {
						//fmt.Println("Alt Choice:", choice)
						//fmt.Println("Alt X:", x)
						temp := int(x / choice)
						//fmt.Println("Temp ", temp)
						x = int(math.Min(float64(temp), float64(choice)))
						//x = x / choice
						solution = solution + 1
					}
				}
			}
		}
		numCases--
		fmt.Println(solution)
	}

}

package main

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

// var reader *bufio.Reader = bufio.NewReader(os.Stdin)
// var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
// func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numCases, _ := strconv.Atoi(scanner.Text())
	for numCases > 0 {
		// calculate all divisors
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		if x == 1 {
			fmt.Println(0)
		} else if x == 2 {
			fmt.Println(1)
		} else if x%2 == 0 {
			fmt.Println(2)
		} else {
			fmt.Println(3)
		}

		numCases--

	}

}

package main

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

// var reader *bufio.Reader = bufio.NewReader(os.Stdin)
// var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

// func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
// func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numCases, _ := strconv.Atoi(scanner.Text())
	for numCases > 0 {
		// calculate all divisors
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		if x == 1 {
			fmt.Println(0)
			numCases--
			continue
		}
		if x == 2 {
			fmt.Println(1)
			numCases--
			continue
		}
		if x%2 == 0 {
			//even
			fmt.Println(2)
			numCases--
			continue
		} else {
			//odd
			fmt.Println(3)
			numCases--
			continue
		}

	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	var n []int64
	for i := 0; i < t; i++ {
		var j int64
		fmt.Scanln(&j)
		n = append(n, j)
	}
	for _, k := range n {
		compute(k, 0)
	}
}

func compute(n, steps int64) {
	if n == 1 {
		fmt.Printf("%d\n", steps)
	} else {
		steps++
		s := smallestFactor(n)
		if s == n {
			n--
		} else {
			n = s
		}
		compute(n, steps)
	}
}
func smallestFactor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	var i int64
	for i = 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return i
		}
	}
	return n
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	var n []int64
	for i := 0; i < t; i++ {
		var j int64
		fmt.Scanln(&j)
		n = append(n, j)
	}
	for _, k := range n {
		compute(k, 0)
	}
}

func compute(n, steps int64) {
	if n == 1 {
		fmt.Printf("%d\n", steps)
	} else {
		s := smallestFactor(n)
		if s == n {
			n--
			steps++
		} else {
			n = s
			steps++
		}
		compute(n, steps)
	}
}
func smallestFactor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	var i int64
	for i = 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return i
		}
	}
	return n
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)
	var n []int64
	for t != 0 {
		var j int64
		fmt.Scanln(&j)
		n = append(n, j)
		t--
	}
	for _, k := range n {
		compute(k, 0)
	}
}

func compute(n, steps int64) {
	if n == 1 {
		fmt.Printf("%d\n", steps)
	} else {
		steps++
		s := smallestFactor(n)
		if s == n {
			n--
		} else {
			n = s
		}
		compute(n, steps)
	}
}
func smallestFactor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	// this goddamn thing is special case
	if n%5 == 0 {
		return n - 1
	}
	var i int64
	for i = 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return i
		}
	}
	return n
}


Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, or a - b, or a × b.After n - 1 steps there is only one number left. Can you make this number equal to 24?

The first line contains a single integer n (1 ≤ n ≤ 105).

If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes). If there is a way to obtain 24 as the result number, in the following n - 1 lines print the required operations an operation per line. Each operation should be in form: "a op b = c". Where a and b are the numbers you've picked at this operation; op is either "+", or "-", or "*"; c is the result of corresponding operation. Note, that the absolute value of c mustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces. If there are multiple valid answers, you may print any of them.

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/468/A

package main

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

func Solve(n int) []string {
	steps := []string{}
	if n >= 4 && n%2 == 0 {
		steps = append(steps, "4 * 3 = 12")
		steps = append(steps, "12 * 2 = 24")
		steps = append(steps, "24 * 1 = 24")
	} else if n >= 4 && n%2 == 1 {
		steps = append(steps, "1 + 5 = 6")
		steps = append(steps, "6 * 4 = 24")
		steps = append(steps, "3 - 2 = 1")
		steps = append(steps, "24 * 1 = 24")
	}
	if n > 4 {
		x := n
		y := n - 1
		for y > 4 {
			s := fmt.Sprintf("%d - %d = 1", x, y)
			steps = append(steps, s)
			steps = append(steps, "24 * 1 = 24")
			x -= 2
			y -= 2
		}
	}
	return steps
}

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

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

	steps := Solve(n)
	if len(steps) > 0 {
		fmt.Fprintf(writer, "YES\n")
		for _, step := range steps {
			fmt.Fprintf(writer, "%s\n", step)
		}
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
}

package main

import (
	"fmt"
)

func print_4() {
	fmt.Println("1 * 2 = 2")
	fmt.Println("2 * 3 = 6")
	fmt.Println("4 * 6 = 24")
}

func print_5() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("5 + -1 = 4")
	fmt.Println("4 + 4 = 8")
	fmt.Println("8 * 3 = 24")
}

func print_6() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 - 6 = -7")
	fmt.Println("-7 - 5 = -12")
	fmt.Println("4 * 3 = 12")
	fmt.Println("12 - -12 = 24")
}

func print_7() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 - 7 = -8")
	fmt.Println("-8 - 6 = -14")
	fmt.Println("3 - 5 = -2")
	fmt.Println("-14 * -2 = 28")
	fmt.Println("28 - 4 = 24")
}

func main() {
	var n, i int
	fmt.Scanf("%d\n", &n)
	if n < 4 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		switch n {
		case 4:
			print_4()
			break
		case 5:
			print_5()
			break
		case 6:
			print_6()
			break
		case 7:
			print_7()
			break
		default:
			q := 0
			for i = n; i > 7; i -= 4 {
				fmt.Printf("%d - %d = 1\n", i, i-1)
				fmt.Printf("%d - %d = -1\n", i-3, i-2)
				fmt.Printf("1 + -1 = 0\n")
				q++
			}
			switch i {
			case 4:
				print_4()
				break
			case 5:
				print_5()
				break
			case 6:
				print_6()
				break
			case 7:
				print_7()
				break
			}
			for i = 0; i < q; i++ {
				fmt.Printf("0 + 24 = 24\n")
			}
		}
	}
}

package main

import (
	"fmt"
)

func print_4() {
	fmt.Println("1 * 2 = 2")
	fmt.Println("2 * 3 = 6")
	fmt.Println("4 * 6 = 24")
}

func print_5() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("5 + -1 = 4")
	fmt.Println("4 + 4 = 8")
	fmt.Println("8 + 3 = 24")
}

func print_6() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -6 = -7")
	fmt.Println("-7 + -5 = -12")
	fmt.Println("4 * 3 = 12")
	fmt.Println("12 - -12 = 24")
}

func print_7() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -7 = -8")
	fmt.Println("-8 + -6 = -14")
	fmt.Println("3 - 5 = -2")
	fmt.Println("-14 * -2 = 28")
	fmt.Println("28 - 4 = 24")
}

func main() {
	var n, i int
	fmt.Scanf("%d\n", &n)
	if n < 4 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		switch n {
		case 4:
			print_4()
			break
		case 5:
			print_5()
			break
		case 6:
			print_6()
			break
		case 7:
			print_7()
			break
		default:
			q := 0
			for i = n; i > 7; i -= 4 {
				fmt.Printf("%d - %d = 1\n", i, i-1)
				fmt.Printf("%d - %d = -1\n", i-2, i-3)
				fmt.Printf("1 + -1 = 0\n")
				q++
			}
			switch i {
			case 4:
				print_4()
				break
			case 5:
				print_5()
				break
			case 6:
				print_6()
				break
			case 7:
				print_7()
				break
			}
			for i = 0; i < q; i++ {
				fmt.Printf("0 + 24 = 24\n")
			}
		}
	}
}

package main

import (
	"fmt"
)

func print_4() {
	fmt.Println("1 * 2 = 2")
	fmt.Println("2 * 3 = 6")
	fmt.Println("4 * 6 = 24")
}

func print_5() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("5 + -1 = 4")
	fmt.Println("4 + 4 = 8")
	fmt.Println("8 + 3 = 24")
}

func print_6() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -6 = -7")
	fmt.Println("-7 + -5 = -12")
	fmt.Println("4 * 3 = 12")
	fmt.Println("12 - -12 = 24")
}

func print_7() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -7 = -8")
	fmt.Println("-8 + -6 = -14")
	fmt.Println("3 - 5 = -2")
	fmt.Println("-14 * -2 = 28")
	fmt.Println("28 - 4 = 24")
}

func main() {
	var n, i int
	fmt.Scanf("%d\n", &n)
	if n < 4 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		switch n {
		case 4:
			print_4()
			break
		case 5:
			print_5()
			break
		case 6:
			print_6()
			break
		case 7:
			print_7()
			break
		default:
			q := 0
			for i = n; i > 7; i -= 4 {
				fmt.Printf("%d - %d = 1\n", i, i-1)
				fmt.Printf("%d - %d = -1\n", i-3, i-2)
				fmt.Printf("1 + -1 = 0\n")
				q++
			}
			switch i {
			case 4:
				print_4()
				break
			case 5:
				print_5()
				break
			case 6:
				print_6()
				break
			case 7:
				print_7()
				break
			}
			for i = 0; i < q; i++ {
				fmt.Printf("0 + 24 = 24\n")
			}
		}
	}
}

package main

import (
	"fmt"
)

func print_4() {
	fmt.Println("1 * 2 = 2")
	fmt.Println("2 * 3 = 6")
	fmt.Println("4 * 6 = 24")
}

func print_5() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("5 + -1 = 4")
	fmt.Println("4 + 4 = 8")
	fmt.Println("8 * 3 = 24")
}

func print_6() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 - 6 = -7")
	fmt.Println("-7 - 5 = -12")
	fmt.Println("4 * 3 = 12")
	fmt.Println("12 - -12 = 24")
}

func print_7() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -7 = -8")
	fmt.Println("-8 + -6 = -14")
	fmt.Println("3 - 5 = -2")
	fmt.Println("-14 * -2 = 28")
	fmt.Println("28 - 4 = 24")
}

func main() {
	var n, i int
	fmt.Scanf("%d\n", &n)
	if n < 4 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		switch n {
		case 4:
			print_4()
			break
		case 5:
			print_5()
			break
		case 6:
			print_6()
			break
		case 7:
			print_7()
			break
		default:
			q := 0
			for i = n; i > 7; i -= 4 {
				fmt.Printf("%d - %d = 1\n", i, i-1)
				fmt.Printf("%d - %d = -1\n", i-3, i-2)
				fmt.Printf("1 + -1 = 0\n")
				q++
			}
			switch i {
			case 4:
				print_4()
				break
			case 5:
				print_5()
				break
			case 6:
				print_6()
				break
			case 7:
				print_7()
				break
			}
			for i = 0; i < q; i++ {
				fmt.Printf("0 + 24 = 24\n")
			}
		}
	}
}

package main

import (
	"fmt"
)

func print_4() {
	fmt.Println("1 * 2 = 2")
	fmt.Println("2 * 3 = 6")
	fmt.Println("4 * 6 = 24")
}

func print_5() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("5 + -1 = 4")
	fmt.Println("4 + 4 = 8")
	fmt.Println("8 + 3 = 24")
}

func print_6() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 - 6 = -7")
	fmt.Println("-7 - 5 = -12")
	fmt.Println("4 * 3 = 12")
	fmt.Println("12 - -12 = 24")
}

func print_7() {
	fmt.Println("1 - 2 = -1")
	fmt.Println("-1 + -7 = -8")
	fmt.Println("-8 + -6 = -14")
	fmt.Println("3 - 5 = -2")
	fmt.Println("-14 * -2 = 28")
	fmt.Println("28 - 4 = 24")
}

func main() {
	var n, i int
	fmt.Scanf("%d\n", &n)
	if n < 4 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		switch n {
		case 4:
			print_4()
			break
		case 5:
			print_5()
			break
		case 6:
			print_6()
			break
		case 7:
			print_7()
			break
		default:
			q := 0
			for i = n; i > 7; i -= 4 {
				fmt.Printf("%d - %d = 1\n", i, i-1)
				fmt.Printf("%d - %d = -1\n", i-3, i-2)
				fmt.Printf("1 + -1 = 0\n")
				q++
			}
			switch i {
			case 4:
				print_4()
				break
			case 5:
				print_5()
				break
			case 6:
				print_6()
				break
			case 7:
				print_7()
				break
			}
			for i = 0; i < q; i++ {
				fmt.Printf("0 + 24 = 24\n")
			}
		}
	}
}


Arkady has a playlist that initially consists of $$$n$$$ songs, numerated from $$$1$$$ to $$$n$$$ in the order they appear in the playlist. Arkady starts listening to the songs in the playlist one by one, starting from song $$$1$$$. The playlist is cycled, i. e. after listening to the last song, Arkady will continue listening from the beginning.Each song has a genre $$$a_i$$$, which is a positive integer. Let Arkady finish listening to a song with genre $$$y$$$, and the genre of the next-to-last listened song be $$$x$$$. If $$$\operatorname{gcd}(x, y) = 1$$$, he deletes the last listened song (with genre $$$y$$$) from the playlist. After that he continues listening normally, skipping the deleted songs, and forgetting about songs he listened to before. In other words, after he deletes a song, he can't delete the next song immediately.Here $$$\operatorname{gcd}(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.For example, if the initial songs' genres were $$$[5, 9, 2, 10, 15]$$$, then the playlist is converted as follows: [5, 9, 2, 10, 15] $$$\to$$$ [5, 9, 2, 10, 15] $$$\to$$$ [5, 2, 10, 15] (because $$$\operatorname{gcd}(5, 9) = 1$$$) $$$\to$$$ [5, 2, 10, 15] $$$\to$$$ [5, 2, 10, 15] $$$\to$$$ [5, 2, 10, 15] $$$\to$$$ [5, 2, 10, 15] $$$\to$$$ [5, 2, 10, 15] $$$\to$$$ [5, 10, 15] (because $$$\operatorname{gcd}(5, 2) = 1$$$) $$$\to$$$ [5, 10, 15] $$$\to$$$ [5, 10, 15] $$$\to$$$ ... The bold numbers represent the two last played songs. Note that after a song is deleted, Arkady forgets that he listened to that and the previous songs.Given the initial playlist, please determine which songs are eventually deleted and the order these songs are deleted.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of songs. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the genres of the songs. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single line. First, print a single integer $$$k$$$ — the number of deleted songs. After that print $$$k$$$ distinct integers: deleted songs in the order of their deletion.

NoteExplanation of the first test case is given in the statement.In the second test case, the playlist is converted as follows: [1, 2, 4, 2, 4, 2] $$$\to$$$ [1, 2, 4, 2, 4, 2] $$$\to$$$ [1, 4, 2, 4, 2] (because $$$\operatorname{gcd}(1, 2) = 1$$$) $$$\to$$$ [1, 4, 2, 4, 2] $$$\to$$$ [1, 4, 2, 4, 2] $$$\to$$$ [1, 4, 2, 4, 2] $$$\to$$$ [1, 4, 2, 4, 2] $$$\to$$$ [1, 4, 2, 4, 2] $$$\to$$$ [4, 2, 4, 2] (because $$$\operatorname{gcd}(2, 1) = 1$$$) $$$\to$$$ [4, 2, 4, 2] $$$\to$$$ ...In the third test case, the playlist is converted as follows: [1, 2] $$$\to$$$ [1, 2] $$$\to$$$ [1] (because $$$\operatorname{gcd}(1, 2) = 1$$$) $$$\to$$$ [1] $$$\to$$$ [1] (Arkady listened to the same song twice in a row) $$$\to$$$ [] (because $$$\operatorname{gcd}(1, 1) = 1$$$).The fourth test case is same as the third after deletion of the second song.In the fifth test case, the same song is listened to over and over again, but since $$$\operatorname{gcd}(2, 2) \ne 1$$$, it is not deleted.

package main
import (
	"bufio"
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		r := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			r[i] = (i + 1) % n
		}
		q := []int{}
		for i, v := range a {
			if gcd(v, a[r[i]]) == 1 {
				q = append(q, i)
			}
		}
		p := []interface{}{}
		b := make([]bool, n)
		for len(q) > 0 {
			i := q[0]
			q = q[1:]
			if b[i] {
				continue
			}
			if !b[r[i]] {
				p = append(p, r[i]+1)
				b[r[i]] = true
			}
			r[i] = r[r[i]]
			if gcd(a[i], a[r[i]]) == 1 {
				q = append(q, i)
			}
		}
		Fprint(out, len(p), " ")
		Fprintln(out, p...)
	}
}
func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1483B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	type node struct {
		next *node
		v, i int
	}
	type lst struct{ h, t *node }

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ls := []lst{}
		for i, cur := 0, (&node{}); i < n; {
			h := &node{v: a[i], i: i + 1}
			t := h
			cur.next = t
			cur = t
			for i++; i < n && gcd(a[i], a[i-1]) > 1; i++ {
				t = &node{v: a[i], i: i + 1}
				cur.next = t
				cur = t
			}
			ls = append(ls, lst{h, t})
		}
		ans := []interface{}{}
		for len(ls) > 1 {
			tmp := ls
			ls = nil
			cd := false
			for i, n := 0, len(tmp); i < n; {
				p := tmp[i]
				for i++; i < n && gcd(tmp[i-1].t.v, tmp[i].h.v) > 1; i++ {
					tmp[i-1].t.next = tmp[i].h
					p.t = tmp[i].t
				}
				ls = append(ls, p)
				if i < n {
					p := tmp[i]
					ans = append(ans, p.h.i)
					if p.h != p.t {
						tmp[i].h = p.h.next
					} else {
						i++
						if i == n {
							cd = true
						}
					}
				}
			}
			if len(ls) == 1 {
				break
			}
			if cd {
				continue
			}
			if p := ls[0]; gcd(ls[len(ls)-1].t.v, p.h.v) == 1 {
				ans = append(ans, p.h.i)
				if p.h != p.t {
					ls[0].h = p.h.next
				} else {
					ls = ls[1:]
				}
			}
		}
		for h, t := ls[0].h, ls[0].t; gcd(h.v, t.v) == 1; h = h.next {
			ans = append(ans, h.i)
			if h == t {
				break
			}
		}
		Fprint(out, len(ans), " ")
		Fprintln(out, ans...)
	}
}

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


This problem differs from the next one only in the presence of the constraint on the equal length of all numbers $$$a_1, a_2, \dots, a_n$$$. Actually, this problem is a subtask of the problem D2 from the same contest and the solution of D2 solves this subtask too.A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.Let's denote a function that alternates digits of two numbers $$$f(a_1 a_2 \dots a_{p - 1} a_p, b_1 b_2 \dots b_{q - 1} b_q)$$$, where $$$a_1 \dots a_p$$$ and $$$b_1 \dots b_q$$$ are digits of two integers written in the decimal notation without leading zeros.In other words, the function $$$f(x, y)$$$ alternately shuffles the digits of the numbers $$$x$$$ and $$$y$$$ by writing them from the lowest digits to the older ones, starting with the number $$$y$$$. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.For example: $$$$$$f(1111, 2222) = 12121212$$$$$$ $$$$$$f(7777, 888) = 7787878$$$$$$ $$$$$$f(33, 44444) = 4443434$$$$$$ $$$$$$f(555, 6) = 5556$$$$$$ $$$$$$f(111, 2222) = 2121212$$$$$$Formally,  if $$$p \ge q$$$ then $$$f(a_1 \dots a_p, b_1 \dots b_q) = a_1 a_2 \dots a_{p - q + 1} b_1 a_{p - q + 2} b_2 \dots a_{p - 1} b_{q - 1} a_p b_q$$$;  if $$$p < q$$$ then $$$f(a_1 \dots a_p, b_1 \dots b_q) = b_1 b_2 \dots b_{q - p} a_1 b_{q - p + 1} a_2 \dots a_{p - 1} b_{q - 1} a_p b_q$$$. Mishanya gives you an array consisting of $$$n$$$ integers $$$a_i$$$. All numbers in this array are of equal length (that is, they consist of the same number of digits). Your task is to help students to calculate $$$\sum_{i = 1}^{n}\sum_{j = 1}^{n} f(a_i, a_j)$$$ modulo $$$998\,244\,353$$$.

The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of elements in the array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. All numbers $$$a_1, a_2, \dots, a_n$$$ are of equal length (that is, they consist of the same number of digits).

Print the answer modulo $$$998\,244\,353$$$.

package main

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

/* solution */

const mod = 998244353

func solve() {

	tens := make([]int64, 21)
	tens[1] = 1
	for i := 2; i <= 20; i++ {
		tens[i] = (10 * tens[i-1]) % mod
	}

	n := readInt()
	a := make([]int64, n)
	l := make([]int64, 11)

	for i := 0; i < n; i++ {
		v := readInt64()
		a[i] = v
		cnt := 0
		for ; v > 0; v /= 10 {
			cnt++
		}
		l[cnt]++
	}

	ans := int64(0)

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

		for v, idx := a[i], 1; v > 0; v, idx = v/10, idx+1 {

			digit := v % 10

			for k := 1; k <= 10; k++ {

				if k >= idx {
					ans = (ans + (digit*l[k]*tens[idx*2])%mod) % mod
				} else {
					ans = (ans + (digit*l[k]*tens[k+idx])%mod) % mod
				}

				if k >= idx-1 {
					ans = (ans + (digit*l[k]*tens[idx*2-1])%mod) % mod
				} else {
					ans = (ans + (digit*l[k]*tens[k+idx])%mod) % mod
				}

			}

		}

	}

	printInt64(ans)

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

const (
	MAXN = int(1e5 + 7)
	MOD  = int64(998244353)
)

var a [MAXN]int64

func main() {
	input, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return
	}
	inputReader := bytes.NewReader(input)
	var N int
	_, _ = fmt.Fscanf(inputReader, "%d\n", &N)
	for i := 1; i < N; i++ {
		_, _ = fmt.Fscanf(inputReader, "%d ", &a[i])
		//fmt.Println(a[i])
	}
	_, _ = fmt.Fscanf(inputReader, "%d\n", &a[N])
	var ans  int64 = 0
	length:=0
	for t:=a[1];t>0;t/=10{
		length++
	}
	power:= func(a,b int)int64 {
		var ans int64=1
		for i:=0;i<b;i++{
			ans*=int64(a)
		}
		return ans
	}

	for i:=1;i<=N;i++ {
		var digit,val int64
		digit,val=1,a[i]
		var constVal =digit+digit*power(10,1)
		for val>0 {
			//fmt.Println(constVal)
			num:=val%10
			ans=(ans+int64(N)*constVal%MOD*num%MOD)%MOD
			val/=10
			constVal=constVal*100%MOD
		}
	}
	fmt.Println(ans)
}

package main

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

var (
	arr [100005]int64
)

const (
	mod = 998244353
)

func modMultiply(a int64, b int64) int64 {
	return ((a % mod) * (b % mod)) % mod
}

func modAdd(a int64, b int64) int64 {
	return ((a % mod) + (b % mod)) % mod
}

func sumOfNumber(n int64, num int64) int64 {
	var v, d, sum int64
	sum = 0
	for v = 1; num > 0; num, v = num/10, v*100 {
		d = num % 10
		sum = modAdd(sum, modMultiply(modMultiply(d, n), v))
		sum = modAdd(sum, modMultiply(modMultiply(modMultiply(d, n), v), 10))
	}
	return sum
}

func main() {
	var n, i int64

	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}

	var ans int64
	for i = 0; i < n; i++ {
		ans = modAdd(ans, sumOfNumber(n, arr[i]))
	}

	fmt.Println(ans)
}

package main

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

var (
	// mod int64
	arr [100005]int64
	mod int64
)

// const (
// 	mod = 998244353
// )

func modMultiply(a int64, b int64) int64 {
	return ((a % mod) * (b % mod)) % mod
}

func modAdd(a int64, b int64) int64 {
	return ((a % mod) + (b % mod)) % mod
}

func sumOfNumber(n int64, num int64) int64 {
	var v, d, sum int64
	sum = 0
	for v = 1; num > 0; num, v = num/10, v*100 {
		d = num % 10
		sum = modAdd(sum, modMultiply(modMultiply(d, n), v))
		sum = modAdd(sum, modMultiply(modMultiply(modMultiply(d, n), v), 10))
	}
	return sum
}

func main() {
	var n, i int64

	mod = 998244353
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}

	var ans int64
	for i = 0; i < n; i++ {
		ans = modAdd(ans, sumOfNumber(n, arr[i]))
	}

	fmt.Println(ans)
}

/*
URL:
https://codeforces.com/problemset/problem/1195/D1
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n int
	A []string
)

func main() {
	n = ReadInt()
	for i := 0; i < n; i++ {
		str := ReadString()
		str = string(Reverse([]rune(str)))
		A = append(A, str)
	}

	l := int64(len(A[0]))

	ans := int64(0)
	for i := 0; i < n; i++ {
		left, right := int64(0), int64(0)

		S := A[i]
		for j := int64(0); j < l; j++ {
			d := int64(S[j] - '0')
			left += d * modpow(10, int64(2*j+1), MOD)
			left %= MOD
			right += d * modpow(10, int64(2*j), MOD)
			right %= MOD
		}

		// PrintfDebug("left : %v\n", left)
		// PrintfDebug("right: %v\n", right)

		left *= int64(n)
		left %= MOD
		right *= int64(n)
		right %= MOD

		ans += left + right
		ans %= MOD
	}
	fmt.Println(ans)
}

func Reverse(A []rune) []rune {
	res := []rune{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

// ModInv returns $a^{-1} mod m$ by Fermat's little theorem.
// O(1), but C is nearly equal to 30 (when m is 1000000000+7).
func ModInv(a, m int64) int64 {
	return modpow(a, m-2, m)
}

func modpow(a, e, m int64) int64 {
	if e == 0 {
		return 1
	}

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

	return a * modpow(a, e-1, m) % m
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	sort.Ints(a)
	sum := int64(0)
	for i := 0; i < n; i++ {
		sum += (second(a[i]) + first(a[i])) * int64(n)
		sum %= mod
	}
	fmt.Fprintf(out, "%d\n", sum)
}

func first(a int) int64 {
	ans := int64(0)
	base := int64(10)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}

func second(a int) int64 {
	ans := int64(0)
	base := int64(1)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}

package main

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

func getD(x, y int64) int64 {
	return ((x % (y * 10)) - x%y) / y
}
func tranR(p, mod int64) int64 {
	y := int64(1)
	z := int64(1)
	res := int64(0)
	for x := 1; x <= 10; x++ {
		res = (res + getD(p, y)*z) % mod
		y = (y * 10)
		z = (z * 100) % mod
	}
	return res
}

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

	n := int64(0)
	x := int64(0)
	mod := int64(998244353)
	fmt.Fscanf(input, "%d\n", &n)
	ans := int64(0)
	for i := int64(0); i < n; i++ {
		fmt.Fscanf(input, "%d", &x)
		ans = ((((tranR(x, mod)*n)%mod)*11)%mod + ans) % mod
	}
	fmt.Println(ans)
}

package main

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

var (
	// mod int64
	arr [100005]int64
)

const (
	mod = 998244353
)

func modMultiply(a int64, b int64) int64 {
	return (a * b) % mod
}

func modAdd(a int64, b int64) int64 {
	return (a + b) % mod
}

func sumOfNumber(n int64, num int64) int64 {
	var v, d, sum int64
	sum = 0
	for v = 1; num > 0; num, v = num/10, v*100 {
		d = num % 10
		sum = modAdd(sum, modMultiply(modMultiply(d, n), v))
		sum = modAdd(sum, modMultiply(modMultiply(modMultiply(d, n), v), 10))
	}
	return sum
}

func main() {
	var n, i int64
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}

	var ans int64
	for i = 0; i < n; i++ {
		ans = modAdd(ans, sumOfNumber(n, arr[i]))
	}

	fmt.Println(ans)
}


There are n points on a straight line, and the i-th point among them is located at xi. All these coordinates are distinct.Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.

The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points. The second line contains a sequence of integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.

Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.

NoteIn the first example you can add one point with coordinate 0.In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.

package main

import "fmt"
import "sort"
import "bufio"
import "os"
func gcd(x int, y int) int {
	if y==0 {
	    return x
	}
	return gcd(y,x%y)
}
func main() {
    in := bufio.NewReader(os.Stdin)
	var n,dif int
	fmt.Fscan(in, &n)
	x := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x[i])
	}
	sort.Ints(x)
	dif=x[1]-x[0]
	for i := 2; i < n; i++ {
		dif=gcd(dif,x[i]-x[i-1])
	}
	fmt.Println((x[n-1]-x[0])/dif-n+1)
}

package main

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

func gcd(x, y int) int {
 for y != 0 {
  x, y = y, x%y
 }
 return x
}

func solve() {
	n := readInt()
	a := readIntArray(n)
	res := make([]int, n-1)
	// sort.Sort(int(a))
     sort.Ints(a)

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

	for i:= 2; i < n-1;i++ {
		ans = gcd(ans,res[i])
	}

	aa := int64(0)

	for i:= 0;i < n-1;i++ {
		aa = aa + int64(res[i]/ans - 1)
	}

	fmt.Print(aa)
}

type Int64 []int64

func (a Int64) Len() int           { return len(a) }
func (a Int64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Int64) Less(i, j int) bool { return a[i] < a[j] }

const INF = math.MaxInt32

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

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

func main() {
	var n int

	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	sort.Ints(a)

	dist := a[1] - a[0]
	for i := 1;i < len(a) - 1;i ++ {
		dist = gcd(dist, a[i + 1] - a[i])
	}
	ans := 0
	for i := 0;i < len(a) - 1;i ++ {
		ans += ((a[i + 1] - a[i]) / dist - 1)
	}
	fmt.Printf("%d", ans)
}

package main

import "fmt"
import "bufio"
import "os"
import "math/rand"
import "sort"

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	a := make([]int, n, n)
	mv, xv := 2147483647, -2147483648
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		if a[i] < mv {
			mv = a[i]
		}
		if a[i] > xv {
			xv = a[i]
		}
	}
	for i := 0; i < n; i++ {
		j := rand.Intn(i + 1)
		a[i], a[j] = a[j], a[i]
	}
	sort.Ints(a)
	difs := 0
	for i := 1; i < n; i++ {
		difs = gcd(difs, a[i] - a[i-1])
	}
	kur := (a[n-1] - a[0]) / difs
	fmt.Println(kur - n + 1)
}

package main

import "fmt"
import "sort"
import "bufio"
import "os"

func f(a, b int) int {
	var c int
	c = 1
	for i := 0; a != 0; i++ {
	    c = b
	    b = a
	    var temp int = c % b
	    a = temp
	    c = b
	}

	return c
}

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	aa := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &aa[i])
	}

	sort.Ints(aa)
	bb := make([]int, n - 1, n - 1)

	for i := 0; i < n - 1; i++ {
	    bb[i] = aa[i + 1] - aa[i]
	}

    var answer int
    answer = f(bb[1], bb[0])

    for i := 2; i < n - 1; i++ {
        answer = f(answer, bb[i]);
    }
    fmt.Println((aa[n-1] - aa[0]) / answer + 1 - n)
}

package main

import "fmt"
import "math/rand"
import "sort"
import "bufio"
import "os"

func f(a, b int) int {
	var c int
	c = 1
	for i := 0; a != 0; i++ {
	    c = b
	    b = a
	    var temp int = c % b
	    a = temp
	    c = b
	}

	return c
}

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	aa := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &aa[i])
	}

	for i := 0; i < n; i++ {
		j := rand.Intn(i+1)
		aa[i], aa[j] = aa[j], aa[i]
	}

	sort.Ints(aa)
	bb := make([]int, n - 1, n - 1)

	for i := 0; i < n - 1; i++ {
	    bb[i] = aa[i + 1] - aa[i]
	}

    var answer int
    answer = f(bb[1], bb[0])

    for i := 2; i < n - 1; i++ {
        answer = f(answer, bb[i]);
    }
    fmt.Println((aa[n-1] - aa[0]) / answer + 1 - n)
}

package main

import "bufio"
import "os"
import "fmt"
import "sort"

func main() {
	var n, k, res int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	a := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)

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

	res = 0
	if (k != 0) {
		for i := 0; i < n - 1; i++ {
		    res += a[i] / k
		}
		res -= n - 1
	}

	fmt.Println(res)
}

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

package main

import "fmt"
import "sort"
import "bufio"
import "os"

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func gcd(a int, b int) int {
	if a < b {
		return gcd(b, a)
	}
	for b != 0 {
		t := a % b
		a = b
		b = t
	}
	return a
}
func main() {
  var n int
  fmt.Fscan(in, &n)
  x := make([]int, n)
  for i := 0; i < n; i++ {
      fmt.Fscan(in, &x[i])
  }
  sort.Ints(x)
  var nd int
  nd = 0
  for i := 1; i < n; i++ {
      nd = gcd (x[i] - x[i-1], nd)
  }
  var m int
  m = 0
  for i := 1; i < n; i++ {
      m = m - 1 + (x[i] - x[i-1]) / nd
  }

  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  fmt.Fprintln(out, m)
}

package main
import "fmt"
import "sort"
import "bufio"
import "os"
func main(){
	var n,c,d,f,gcd,ans int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n);
	a:= make([]int,n,n)
	for i:=0; i < n; i++{
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)
//	for i:=0; i < n; i++{
//		fmt.Printf("%d", a[i])
//	}
	c=a[1] - a[0]
	d=a[2] - a[1]
	for d != 0{
	      f = c % d
	      c = d
	      d = f
	}
	gcd = c

	for i:=2; i < n; i++{
	      c = gcd
	      d = a[i] - a[i-1]
	      if (d%gcd == 0){
	            continue
	      }
		for d != 0{
	      f = c % d
	      c = d
	      d = f
	}
	gcd = c
	}
	for i:=1; i < n; i++{
	      ans = ans + (a[i]-a[i-1])/gcd - 1
	}
	fmt.Printf("%d", ans)
}

package main
import "fmt"
import "math/rand"
import "sort"
import "bufio"
import "os"
func main(){
	var n,c,d,f,gcd,ans int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n);
	a:= make([]int,n,n)
	for i:=0; i < n; i++{
		fmt.Fscan(in, &a[i])
	}
	for i:=0; i < n; i++{
	     	c = rand.Intn(i + 1)
		a[i], a[c] = a[c], a[i]
	}
	sort.Ints(a)
//	for i:=0; i < n; i++{
//		fmt.Printf("%d", a[i])
//	}
	c=a[1] - a[0]
	d=a[2] - a[1]
	for d != 0{
	      f = c % d
	      c = d
	      d = f
	}
	gcd = c

	for i:=2; i < n; i++{
	      c = gcd
	      d = a[i] - a[i-1]
	      if (d%gcd == 0){
	            continue
	      }
		for d != 0{
	      f = c % d
	      c = d
	      d = f
	}
	gcd = c
	}
	for i:=1; i < n; i++{
	      ans = ans + (a[i]-a[i-1])/gcd - 1
	}
	fmt.Printf("%d", ans)
}

package main

import "fmt"
import "bufio"
import "os"
import "math/rand"
import "sort"

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	a := make([]int, n, n)
	mv, xv := 2147483647, -2147483648
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		if a[i] < mv {
			mv = a[i]
		}
		if a[i] > xv {
			xv = a[i]
		}
	}
	for i := 0; i < n; i++ {
		j := rand.Intn(i + 1)
		a[i], a[j] = a[j], a[i]
	}
	sort.Ints(a)
	difs := 42
	for i := 1; i < n; i++ {
		difs = gcd(difs, a[i] - a[i-1])
	}
	kur := (a[n-1] - a[0]) / difs
	fmt.Println(kur - n + 1)
}

package main

import "fmt"
import "sort"

func gcd(a int, b int) int {
	if a < b {
		return gcd(b, a)
	}
	for b != 0 {
		t := a % b
		a = b
		b = t
	}
	return a
}
func main() {
  var n int
  fmt.Scanln(&n)
  x := make([]int, n)
  for i := 0; i < n; i++ {
      fmt.Scanf("%d\n", &x[i])
  }
  sort.Ints(x)
  var nd int
  nd = 0
  for i := 1; i < n; i++ {
      nd = gcd (x[i] - x[i-1], nd)
  }
  var m int
  m = 0
  for i := 1; i < n; i++ {
      m = m + (x[i] - x[i-1]) / nd - 1
  }
  fmt.Printf("%d\n", m)
}

package main

import "fmt"
import "sort"

func gcd(a int, b int) int {
	if a < b {
		return gcd(b, a)
	}
	for b != 0 {
		t := a % b
		a = b
		b = t
	}
	return a
}
func main() {
  var n int
  fmt.Scanln(&n)
  x := make([]int, n)
  for i := 0; i < n; i++ {
      fmt.Scanf("%d\n", &x[i])
  }
  sort.Ints(x)
  var nd int
  nd = 0
  for i := 1; i < n; i++ {
      nd = gcd (x[i] - x[i-1], nd)
  }
  if nd < 0 {
      nd = -nd
  }
  var m int
  m = 0
  for i := 1; i < n; i++ {
      m = m + (x[i] - x[i-1]) / nd - 1
  }
  fmt.Printf("%d\n", m)
}

package main

import (

	"fmt"

	"math/rand"

)

func quickSort(slice []int) []int {

	length := len(slice)

	if length <= 1 {

		sliceCopy := make([]int, length)

		copy(sliceCopy, slice)

		return sliceCopy

	}

	m := slice[rand.Intn(length)]

	less := make([]int, 0, length)

	middle := make([]int, 0, length)

	more := make([]int, 0, length)

	for _, item := range slice {

		switch {

		case item < m:

			less = append(less, item)

		case item == m:

			middle = append(middle, item)

		case item > m:

			more = append(more, item)

		}

	}

	less, more = quickSort(less), quickSort(more)

	less = append(less, middle...)

	less = append(less, more...)

	return less

}

func gcd(a, b int) int {

	if b == 0 {

		return a

	}

	return gcd(b, a%b)

}

func main() {

	var n int

	fmt.Scanf("%d", &n)

	if n <= 2 {

		fmt.Println(0)

		return

	}

	a := make([]int, n)

	for i := range a {

		fmt.Scanf("%d", &a[i])

	}

	a = quickSort(a)

	g := a[1] - a[0]

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

		g = gcd(g, a[i]-a[i-1])

	}

	var ans int

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

		ans = ans + ((a[i] - a[i-1])/g) - 1

	}

	fmt.Println(ans)

}


There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.Write the program that determines which tasks will be performed and which will be ignored.

The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.  Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n, 1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.

Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.

NoteIn the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.

package main

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

func main() {
	type Tuple struct {
		time    int
		perform int
	}

	sc := NewScanner()
	N, q := sc.NextInt(), sc.NextInt()
	lastTasks := make([]Tuple, N)
	for i := 0; i < q; i++ {
		t, k, d := sc.NextInt(), sc.NextInt(), sc.NextInt()
		p := make([]int, 0, k)
		for q := 0; q < N; q++ {
			if t - lastTasks[q].time < lastTasks[q].perform {
				continue
			}
			p = append(p, q)
			if len(p) == k {
				break
			}
		}
		if len(p) != k {
			fmt.Println(-1)
			continue
		}
		ids := 0
		for _, u := range p {
			lastTasks[u].time = t
			lastTasks[u].perform = d
			ids += u + 1
		}
		fmt.Println(ids)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Petya has n positive integers a1, a2, ..., an. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers. Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.

Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.

NoteIn the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. In the second example the numbers after the restoration can look like: [11, 22, 11].

package main

import (
	"fmt"
	"math"
	"sort"
)

type Pair struct {
	K rune
	V int64
}
type Pairs []Pair

func (s Pairs) Len() int {
	return len(s)
}

func (s Pairs) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s Pairs) Less(i, j int) bool {
	return s[i].V < s[j].V
}

func main() {
	var t int
	leading := make([]bool, 10)
	tab := make([]Pair, 10)
	// fmt.Println(leading)
	// fmt.Println("debut")
	// for ind := 0; ind < len(tab); ind++ {
	// 	fmt.Println(tab[ind])
	// }
	fmt.Scanln(&t)

	for ind := 0; ind < t; ind++ {
		var s string
		fmt.Scanln(&s)
		leading[int(s[0]-'a')] = true
		for k, v := range s {
			c := (len(s) - k - 1)
			tab[int(v-'a')].V += int64(math.Pow10(c))
			tab[int(v-'a')].K = v
		}
	}
	//fmt.Println("arr")
	sort.Sort(Pairs(tab))
	//fmt.Println(leading)
	//fmt.Println(tab)
	//***************
	var lead = false
	var sum_min, count int64
	count, sum_min = 1, 0
	for ind := len(tab) - 1; ind >= 0; ind-- {
		//fmt.Println(int(tab[ind].K - 'a'))
		if tab[ind].K == 0 {
			continue
		}
		if lead == false && leading[int(tab[ind].K-'a')] == false {
			lead = true
			continue
		}
		sum_min += count * tab[ind].V
		count += 1
	}
	fmt.Println(sum_min)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func perm910C(arr []int, i int, f func([]int)) {
	if i == len(arr) {
		f(arr)
		return
	}
	perm910C(arr, i+1, f)
	for j := i + 1; j < len(arr); j++ {
		arr[i], arr[j] = arr[j], arr[i]
		perm910C(arr, i+1, f)
		arr[i], arr[j] = arr[j], arr[i]
	}
}

func Sol910C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	pow10 := [6]int{1, 1e1, 1e2, 1e3, 1e4, 1e5}

	var n int
	var coefs [10]int
	var mustNotZero [10]bool
	for Fscan(in, &n); n > 0; n-- {
		var s string
		Fscan(in, &s)
		mustNotZero[s[0]-'a'] = true
		for i, c := range s {
			coefs[c-'a'] += pow10[len(s)-1-i]
		}
	}

	minVal := 1 << 30
	perm910C([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 0, func(digits []int) {
		val := 0
		for i, d := range digits {
			if d == 0 {
				if mustNotZero[i] {
					return
				}
				continue
			}
			val += coefs[i] * d
		}
		if val < minVal {
			minVal = val
		}
	})
	Fprintln(out, minVal)
}

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

package main

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

var n int32;
var Words[1001] string;
func ReadData() {
  fmt.Scanf("%d", &n);
  reader := bufio.NewScanner(os.Stdin)
  reader.Scan()

  var i int32
  i = 1
  for i <= n {
    reader.Scan()
    Words[i] = reader.Text();

    // fmt.Println(Words[i])
    i++;
  }
}

func Solve() {
  var Ten[10] int64;
  var i int32

  Zero := [10]bool {false, false, false, false, false, false, false, false, false, false};
  Ten[0] = 1
  i = 1;
  for i < 10 {
    Ten[i] = Ten[i - 1] * 10
    i++
  }

  var Coef[10] int64;
  i = 1
  for i <= n {
    c := Words[i][0] - 97
    Zero[c] = true

    for j := 0; j < len(Words[i]); j++ {
      c := Words[i][j] - 97
      Coef[c] += Ten[len(Words[i]) - 1 - j]
    }
    i++;
  }
  var Indices[10] int;
  for i := 0; i < 10; i++ {
    Indices[i] = i;
  }

  for i := 0; i < 10; i++ {
    for j := i + 1; j < 10; j++ {
       if Coef[Indices[i]] < Coef[Indices[j]] {
	 tmp := Indices[i];
         Indices[i] = Indices[j]
	 Indices[j] = tmp
       }
    }
  }

  // for i := 0; i < 10; i++ {
  //   fmt.Println("i:", i, " Ch:", Indices[i], " Coef:", Coef[Indices[i]])
  // }
  var sum int64 = 0
  var current int32 = 1
  var used0 bool = false

  for i := 0; i < 10; i++ {
    var d int = Indices[i]
    if !used0 && !Zero[d] {
      used0 = true
    } else {
      sum += (int64(current) * Coef[d])
      current += 1
    }
  }
  fmt.Println(sum)
}

func main() {
  ReadData();
  Solve()
}