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 a_{i} 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.


-----Input-----

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 a_{i} (1 ≤ a_{i} ≤ 10^4) — the towers' initial heights.


-----Output-----

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.


-----Examples-----
Input
3 2
5 8 5

Output
0 2
2 1
2 3

Input
3 4
2 2 4

Output
1 1
3 2

Input
5 3
8 3 2 6 3

Output
3 3
1 3
1 2
1 3



-----Note-----

In 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.

Difficulty: MEDIUM
Tags: Constructive algorithms

Sorting

Implementation

Greedy algorithms

Complete search
Skill types: Complete search

Sorting

Greedy algorithms

Starter code:

Solutions:
(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
l1 = [[l[i], i + 1] for i in range(n)]
l1.sort()
ans = []
k1 = k
if len(set(l)) == 1:
	print(0, 0)
	exit()
while k:
	k -= 1
	(l1[0][0], l1[n - 1][0]) = (l1[0][0] + 1, l1[n - 1][0] - 1)
	ans.append([l1[n - 1][1], l1[0][1]])
	l1.sort()
	if len(set((l1[i][0] for i in range(n)))) == 1:
		break
l = [l1[i][0] for i in range(n)]
print(max(l) - min(l), end=' ')
print(len(ans))
for i in range(len(ans)):
	print(*ans[i])


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
ans = []
while k >= 0:
	x = 0
	y = 0
	for j in range(n):
		if arr[j] > arr[x]:
			x = j
		if arr[j] < arr[y]:
			y = j
	if k == 0 or arr[x] - arr[y] <= 1:
		print(arr[x] - arr[y], len(ans))
		for j in ans:
			print(j[0], j[1])
		break
	if arr[x] != arr[y]:
		ans.append((x + 1, y + 1))
		arr[x] -= 1
		arr[y] += 1
	k -= 1


(n, k) = [int(x) for x in input().split()]
m = [int(x) for x in input().split()]
a = 1
b = max(m)
c = min(m)
w = []
while a <= k and b > c:
	p = m.index(b)
	q = m.index(c)
	w.append([p + 1, q + 1])
	m[p] -= 1
	m[q] += 1
	b = max(m)
	c = min(m)
	a += 1
print(b - c, end=' ')
print(a - 1)
for c in w:
	print(' '.join(map(str, c)))


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def main():
	(n, k) = mi(line())
	arr = [[e + 1, n] for (e, n) in enumerate(lmi(line()))]
	ans = []
	count = 0
	for _ in range(k + 1):
		(ind1, el1) = min(arr, key=lambda x: x[1])
		(ind2, el2) = max(arr, key=lambda x: x[1])
		if el1 == el2 or el1 == el2 - 1 or count == k:
			break
		else:
			ans.append((ind2, ind1))
			arr[ind1 - 1][1] += 1
			arr[ind2 - 1][1] -= 1
			count += 1
	(_, el1) = min(arr, key=lambda x: x[1])
	(_, el2) = max(arr, key=lambda x: x[1])
	print(el2 - el1, count)
	for (x, y) in ans:
		print(x, y)
main()


(n, k) = map(int, input().split())
(s, i, j) = ('', 0, 10000)
t = [[] for x in range(j + 1)]
for (y, x) in enumerate(map(int, input().split()), 1):
	t[x].append(str(y))
while not t[i]:
	i += 1
while not t[j]:
	j -= 1
while k and i < j:
	(a, b) = (t[j].pop(), t[i].pop())
	s += '\n' + a + ' ' + b
	t[j - 1].append(a)
	t[i + 1].append(b)
	k -= 1
	if not t[i]:
		i += 1
	if not t[j]:
		j -= 1
print(str(j - i) + ' ' + str(s.count(' ')) + s)


f = input()
s = input()
a = f.split(' ')
n = int(a[0])
k = int(a[1])
a = s.split(' ')
i = 0
while i < n:
	a[i] = int(a[i])
	i = i + 1
ans = -1
v1 = list()
v2 = list()
while k > 0:
	posmn = -1
	posmx = -1
	mn = 2 ** 16
	mx = -1
	i = 0
	while i < n:
		if mn > a[i]:
			mn = a[i]
			posmn = i
		if mx < a[i]:
			mx = a[i]
			posmx = i
		i = i + 1
	if mx == mn:
		ans = 0
		break
	v1.append(posmx + 1)
	v2.append(posmn + 1)
	a[posmx] = a[posmx] - 1
	a[posmn] = a[posmn] + 1
	k = k - 1
i = 0
mx = -1
mn = 2 ** 16
while i < n:
	mn = min(mn, a[i])
	mx = max(mx, a[i])
	i = i + 1
ans = mx - mn
print(str(ans) + ' ' + str(len(v1)))
i = 0
while i < len(v1):
	print(str(v1[i]) + ' ' + str(v2[i]))
	i = i + 1


(n, k) = map(int, input().split())
a = list(zip(list(map(int, input().split())), [i for i in range(1, n + 1)]))
a.sort()
add = [0] * n
ans = []
m = 0
while k > 0 and a[0][0] + 1 + add[0] < a[-1][0] + add[-1]:
	l = 0
	while a[l + 1][0] + add[l + 1] == a[l][0] + add[l]:
		l += 1
	r = n - 1
	while a[r][0] + add[r] == a[r - 1][0] + add[r - 1]:
		r -= 1
	add[r] -= 1
	add[l] += 1
	k -= 1
	m += 1
	ans.append([a[r][1], a[l][1]])
print(a[-1][0] + add[-1] - (a[0][0] + add[0]), m)
for i in range(m):
	print(ans[i][0], ans[i][1])


import sys
from collections import defaultdict

def towers(towerList, ops):
	startingOps = ops
	cache = defaultdict(list)
	counter = [0 for _ in range(max(towerList) + 1)]
	prefixList = [0 for _ in range(len(counter))]
	suffixList = [0 for _ in range(len(counter))]
	for (index, ele) in enumerate(towerList):
		counter[ele] += 1
		cache[ele].append(index + 1)
	prefixList[0] = counter[0]
	suffixList[-1] = counter[-1]
	for i in range(1, len(counter)):
		prefixList[i] = prefixList[i - 1] + counter[i]
	for i in range(len(counter) - 2, -1, -1):
		suffixList[i] = suffixList[i + 1] + counter[i]
	low = 0
	high = len(counter) - 1
	lowestScore = 0
	totalOps = 0
	opsList = []
	while ops != 0:
		while prefixList[low] == 0:
			low += 1
		while suffixList[high] == 0 and high > low + 1:
			high -= 1
		if high <= low + 1:
			break
		if prefixList[low] > ops and suffixList[high] > ops:
			break
		prefixList[low] -= 1
		lowBlock = cache[low].pop()
		cache[low + 1].append(lowBlock)
		suffixList[high] -= 1
		highBlock = cache[high].pop()
		cache[high - 1].append(highBlock)
		opsList.append((highBlock, lowBlock))
		ops -= 1
	totalOps = startingOps - ops
	top = 0
	for i in range(len(suffixList) - 1, -1, -1):
		if suffixList[i] != 0:
			top = i
			break
	bottom = 0
	for i in range(len(prefixList)):
		if prefixList[i] != 0:
			bottom = i
			break
	lowestScore = top - bottom
	print(lowestScore, totalOps)
	for (a, b) in opsList:
		print(a, b)

def readinput():
	(n, k) = map(int, sys.stdin.readline().rstrip().split(' '))
	blocks = list(map(int, sys.stdin.readline().rstrip().split(' ')))
	towers(blocks, k)
readinput()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
while k > 0:
	mn = min(a)
	mx = max(a)
	if mn + 1 >= mx:
		break
	for i in range(n):
		if a[i] == mn:
			a[i] += 1
			ans.append(i)
			break
	for i in range(n):
		if a[i] == mx:
			a[i] -= 1
			ans[-1] = (ans[-1], i)
			break
	k -= 1
print(max(a) - min(a), len(ans))
for (a, b) in ans:
	print(b + 1, a + 1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if n == 1:
	print(0, 0)
	exit()
l1 = [[l[i], i + 1] for i in range(n)]
k1 = k
opa = []
while k1 > 0:
	l1 = sorted(l1, key=lambda x: x[0])
	if abs(l1[0][0] - l1[-1][0]) <= 1:
		break
	opa.append(str(l1[-1][1]) + ' ' + str(l1[0][1]))
	l1[0][0] += 1
	l1[-1][0] -= 1
	k1 -= 1
l1 = sorted(l1, key=lambda x: x[0])
print(l1[-1][0] - l1[0][0], k - k1)
for x in opa:
	print(x)


def test(lst):
	for i in range(len(lst) - 1):
		if lst[i] != lst[i + 1]:
			return True
	return False
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
p = []
m = 0
tst = test(a)
s = max(a) - min(a)
while k > 0 and tst and (s > 1):
	i = a.index(max(a))
	j = a.index(min(a))
	(a[i], a[j]) = (a[i] - 1, a[j] + 1)
	p.append([i + 1, j + 1])
	m += 1
	tst = test(a)
	k -= 1
	s = max(a) - min(a)
print(s, m)
for i in p:
	print(*i)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph():
	d = {}
	(v, e) = mi()
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(l, n):
	d = {}
	for i in range(1, n + 1):
		if i not in d.keys():
			d[i] = l[i]
		else:
			d[i].append(l[i])
	return d
(n, k) = mi()
l = li()
a = []
count = 0
if max(l) - min(l) > 0:
	for i in range(k):
		s = max(l) - min(l)
		count += 1
		if s <= 0:
			count -= 1
			break
		x = l.index(max(l))
		y = l.index(min(l))
		a.append(str(x + 1) + ' ' + str(y + 1))
		l[x] -= 1
		l[y] += 1
	print(max(l) - min(l), count)
	for i in range(count):
		print(a[i])
else:
	print(0, 0)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = max(a) - min(a)
answer = []
m = 0
max_s = max(a) - min(a)
if max_s != 0:
	while k != 0:
		if max_s >= max(a) - min(a):
			max_s = max(a) - min(a)
		else:
			break
		max_a = a.index(max(a))
		min_a = a.index(min(a))
		if max_a == min_a:
			break
		answer.append((max_a + 1, min_a + 1))
		a[max_a] -= 1
		a[min_a] += 1
		m += 1
		s = max(a) - min(a)
		k -= 1
	print(s, m)
	for i in answer:
		print(i[0], i[1])
else:
	print(0, 0)


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, k) = zz()
arr = zzz()
cnt = 0
moves = []
for i in range(k):
	ma = arr.index(max(arr))
	mi = arr.index(min(arr))
	if arr[ma] - arr[mi] > 1 and ma != mi:
		arr[ma] -= 1
		arr[mi] += 1
		moves.append([ma + 1, mi + 1])
	else:
		break
	cnt += 1
print(max(arr) - min(arr), cnt)
for i in moves:
	print(*i)


l = input().split()
n = int(l[0])
k = int(l[1])
a = input().split()
ans = []
for i in range(len(a)):
	a[i] = int(a[i])
b = []
for i in range(len(a)):
	b.append(a[i])
ms = max(a) - min(a)
op = 0
dum = 1
while k > 0 and dum == 1:
	k -= 1
	ma = a.index(max(a))
	a[ma] -= 1
	mi = a.index(min(a))
	a[mi] += 1
	if sorted(a) != sorted(b):
		op += 1
		ms = max(a) - min(a)
		b[ma] -= 1
		b[mi] += 1
		ans.append([ma + 1, mi + 1])
	else:
		dum = 0
print(ms, op)
for i in range(len(ans)):
	print(ans[i][0], ans[i][1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = [[a[i], i] for i in range(n)]
d.sort()
cnt = 0
ops = []
while d[n - 1][0] - d[0][0] > 1 and cnt < k:
	ops.append([d[n - 1][1] + 1, d[0][1] + 1])
	d[n - 1][0] -= 1
	d[0][0] += 1
	cnt += 1
	d.sort()
print(d[n - 1][0] - d[0][0], cnt)
for (f, t) in ops:
	print(f, t)


import functools
import operator
info_data = list(map(int, input().split()))
data = list(map(int, input().split()))
aver = functools.reduce(operator.add, data) / info_data[0]
i = 0
result = []
while i < info_data[1]:
	max_v = data[0]
	min_v = data[0]
	max_j = 0
	min_j = 0
	for j in enumerate(data):
		if max_v < j[1]:
			max_v = j[1]
			max_j = j[0]
		if min_v > j[1]:
			min_v = j[1]
			min_j = j[0]
	if data[min_j] < aver:
		data[min_j] += 1
		data[max_j] -= 1
		result.append((max_j, min_j))
	else:
		break
	i += 1
max_v = data[0]
min_v = data[0]
max_j = 0
min_j = 0
for j in enumerate(data):
	if max_v < j[1]:
		max_v = j[1]
		max_j = j[0]
	if min_v > j[1]:
		min_v = j[1]
		min_j = j[0]
print('{} {}'.format(max_v - min_v, i))
for i in result:
	print('{} {}'.format(i[0] + 1, i[1] + 1))


(n, k) = list(map(int, input().split()))
towers = list(map(int, input().split()))
log_moves = []

def max(l):
	m = 0
	for (i, n) in enumerate(l):
		if n > l[m]:
			m = i
	return m

def min(l):
	m = 0
	for (i, n) in enumerate(l):
		if n < l[m]:
			m = i
	return m
mx = max(towers)
mn = min(towers)
min_k = 0
min_unst = towers[mx] - towers[mn]
i = 0
while i < k:
	log_moves.append([mx + 1, mn + 1])
	towers[mx] -= 1
	towers[mn] += 1
	mx = max(towers)
	mn = min(towers)
	unst = towers[mx] - towers[mn]
	i += 1
	if unst < min_unst:
		min_unst = unst
		min_k = i
print('{} {}'.format(min_unst, min_k))
for log in log_moves[:min_k]:
	print('{} {}'.format(*log))


(n, k) = map(int, input().split())
towers = list(map(int, input().split()))
operations = []
instability = 10000
operation = 0
for _ in range(k):
	(minn, maxx) = (min(towers), max(towers))
	min_index = towers.index(minn)
	max_index = towers.index(maxx)
	towers[min_index] += 1
	towers[max_index] -= 1
	(minn, maxx) = (min(towers), max(towers))
	val = maxx - minn
	if val <= instability and min_index != max_index:
		instability = val
		operation += 1
		operations.append((max_index + 1, min_index + 1))
if instability == 10000:
	instability = 0
print(instability, operation)
for i in operations:
	print(*i)


def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return [str(x) for x in stdin.readline().split()]

def arr_enu():
	return [[i + 1, int(x)] for (i, x) in enumerate(stdin.readline().split())]
from sys import stdin
from bisect import *
(n, k) = arr_inp(1)
(a, ans) = (sorted(arr_enu(), key=lambda x: x[1]), [])
for i in range(k):
	if a[-1][1] - a[0][1] <= 1:
		break
	else:
		a[-1][1] -= 1
		a[0][1] += 1
		ans.append([a[-1][0], a[0][0]])
		a.sort(key=lambda x: x[1])
print(a[-1][1] - a[0][1], len(ans))
for i in ans:
	print(*i)


(n, k) = map(int, input().split())
a = [*map(int, input().split())]
q = sum(a)
q = q // n + (q % n != 0)
l = []
m = 0
for i in range(k):
	if max(a) - min(a) <= 1:
		break
	(w, e) = (a.index(max(a)), a.index(min(a)))
	a[w] -= 1
	a[e] += 1
	l += [[w + 1, e + 1]]
	m += 1
print(max(a) - min(a), m)
for i in l:
	print(*i)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
diff = max(l) - min(l)
if diff == 0:
	print(0, 0)
elif diff == 1:
	print(1, 0)
else:
	s = 0
	ans = []
	while s < k:
		x = l.index(min(l))
		y = l.index(max(l))
		if max(l) - min(l) <= 1:
			break
		else:
			s += 1
			l[x] += 1
			l[y] -= 1
			ans.append([y + 1, x + 1])
	print(max(l) - min(l), s)
	for i in range(len(ans)):
		print(*ans[i])


(n, k) = input().split()
list_ = input()
mass = []
result = []
s = 0
n = int(n)
k = int(k)
k_1 = k
summ = ''
i = 0
while i < len(list_):
	if list_[i] == ' ':
		mass.append(int(summ))
		summ = ''
	else:
		summ = summ + list_[i]
		if i == len(list_) - 1:
			mass.append(int(summ))
	i = i + 1
i = 0
index_max = 0
index_men = 0
while i < k:
	max = mass[0]
	men = mass[0]
	for j in range(len(mass)):
		if mass[j] >= max:
			max = mass[j]
			index_max = j
		if mass[j] <= men:
			men = mass[j]
			index_men = j
	if max - men <= 1:
		break
	else:
		mass[index_max] = mass[index_max] - 1
		mass[index_men] = mass[index_men] + 1
		result.append(index_max + 1)
		result.append(index_men + 1)
	k = k - 1
max = mass[0]
men = mass[0]
for j in range(len(mass)):
	if mass[j] > max:
		max = mass[j]
		index_max = j
	if mass[j] < men:
		men = mass[j]
		index_men = j
s = max - men
k_1 = k_1 - k
print(s, k_1)
while True:
	if len(result) > 0:
		print(result.pop(0), result.pop(0))
	else:
		break


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join(map(str, a)) + end)

def minMaxIx(a, n):
	mn = 0
	mx = 0
	for i in range(1, n):
		if a[i] > a[mx]:
			mx = i
		if a[i] < a[mn]:
			mn = i
	return (mn, mx)

def main():
	(n, k) = getf()
	a = getf()
	p = 0
	ps = []
	while True:
		(x, y) = minMaxIx(a, n)
		if x == y or k == 0:
			break
		else:
			a[y] -= 1
			a[x] += 1
			ps += [[y + 1, x + 1]]
			k -= 1
			p += 1
	(x, y) = minMaxIx(a, n)
	putf([a[y] - a[x], p])
	[putf(x) for x in ps]
main()


line = input('')
line = line.split()
amount = int(line[0])
movess = int(line[1])
towers = input('')
towers = towers.split()
towers = list(map(int, towers))
count = 0
insta = max(towers) - min(towers)
moves = []
instaCount = 1
for i in range(movess):
	if insta == 1 or insta == 0:
		break
	else:
		moves.append([towers.index(max(towers)) + 1, towers.index(min(towers)) + 1])
		towers[towers.index(max(towers))] -= 1
		towers[towers.index(min(towers))] += 1
		count += 1
		if max(towers) - min(towers) == insta:
			instaCount = 2
			pass
		else:
			instaCount = 1
			insta = max(towers) - min(towers)
print(str(insta) + ' ' + str(count))
for n in moves:
	print(str(n[0]) + ' ' + str(n[1]))


(numOfTowers, numOfOperations) = map(int, input().split())
heights = list(map(int, input().split()))
l = []
for i in range(numOfOperations):
	max_index = heights.index(max(heights))
	min_index = heights.index(min(heights))
	if min_index != max_index:
		heights[max_index] -= 1
		heights[min_index] += 1
		l.append([max_index + 1, min_index + 1])
print(max(heights) - min(heights), len(l))
for j in l:
	print(' '.join(map(str, j)))


(n, k) = map(int, input().split())
ops = 0
height = list(map(int, input().split()))
ans = []
while ops < k:
	(pos_lo, lo) = min(enumerate(height), key=lambda x: x[1])
	(pos_hi, hi) = max(enumerate(height), key=lambda x: x[1])
	if hi == lo:
		break
	height[pos_lo] += 1
	height[pos_hi] -= 1
	ans.append((pos_hi + 1, pos_lo + 1))
	ops += 1
print(max(height) - min(height), ops)
print('\n'.join((str(x) + ' ' + str(y) for (x, y) in ans)))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, steps) = value()
height = array()
max_possibe = ceil(sum(height) / n) - sum(height) // n
operation = []
ma = height.index(max(height))
mi = height.index(min(height))
while height[ma] - height[mi] != max_possibe and steps > 0:
	steps -= 1
	operation.append((ma + 1, mi + 1))
	height[ma] -= 1
	height[mi] += 1
	ma = height.index(max(height))
	mi = height.index(min(height))
print(height[ma] - height[mi], len(operation))
for i in operation:
	print(*i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
actions = []
for i in range(k):
	max_index = min_index = 0
	max_value = min_value = a[0]
	for (j, value) in enumerate(a):
		if value > max_value:
			max_index = j
			max_value = value
		elif value < min_value:
			min_index = j
			min_value = value
	if max_value == min_value:
		break
	actions.append((max_index, min_index))
	a[max_index] -= 1
	a[min_index] += 1
print(max(a) - min(a), len(actions))
for (i, j) in actions:
	print(i + 1, j + 1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
lst = []
j = count = 0
check = -1
while j < k:
	mini = 10 ** 4 + 3
	maxi = 0
	for i in range(n):
		if maxi < arr[i]:
			max_index = i
			maxi = arr[i]
		if mini > arr[i]:
			min_index = i
			mini = arr[i]
	if maxi - mini > 1:
		count += 1
		arr[max_index] -= 1
		arr[min_index] += 1
		lst.append([max_index + 1, min_index + 1])
	else:
		break
	j += 1
mini = 10 ** 4 + 3
maxi = 0
for i in range(n):
	if maxi < arr[i]:
		maxi = arr[i]
	if mini > arr[i]:
		mini = arr[i]
print(maxi - mini, count)
for j in lst:
	print(*j)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
count = 0
arr = []
for i in range(b):
	minimum = min(l)
	maximum = max(l)
	if maximum - minimum <= 1:
		break
	minindex = l.index(minimum)
	maxindex = l.index(maximum)
	l[minindex] += 1
	l[maxindex] -= 1
	arr.append((maxindex + 1, minindex + 1))
print(max(l) - min(l), len(arr))
print('\n'.join((' '.join(map(str, i)) for i in arr)))


import sys

class Item:

	def __init__(self, i, v):
		self.i = i
		self.v = v

	def __repr__(self):
		return '%s %s' % (self.i, self.v)
(n, k) = sys.stdin.readline().split()
n = int(n)
k = int(k)
tower = sys.stdin.readline().split()
for i in range(len(tower)):
	tower[i] = Item(i + 1, int(tower[i]))
tower = sorted(tower, key=lambda t: t.v)
steps = []
start = 0
end = len(tower) - 1
i = 0
while i < k:
	if tower[start].v < tower[end].v - 1:
		tower[start].v += 1
		tower[end].v -= 1
		step = '%s %s' % (tower[end].i, tower[start].i)
		steps.append(step)
		tower = sorted(tower, key=lambda t: t.v)
		i += 1
	else:
		break
print('%s %s' % (tower[end].v - tower[start].v, i))
for step in steps:
	print(step)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
moves = []
for _ in range(k):
	imin = min(range(len(t)), key=lambda i: t[i])
	imax = max(range(len(t)), key=lambda i: t[i])
	if t[imin] == t[imax]:
		break
	moves.append((imax, imin))
	t[imax] -= 1
	t[imin] += 1
print(max(t) - min(t), len(moves))
for (x, y) in moves:
	print(x + 1, y + 1)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
import heapq
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, k) = iia()
arr = iia()
res = []
while k > 0:
	small = big = 0
	for i in range(1, n):
		if arr[i] < arr[small]:
			small = i
		if arr[i] > arr[big]:
			big = i
	if arr[small] == arr[big] or arr[small] + 1 == arr[big]:
		break
	arr[small] += 1
	arr[big] -= 1
	res.append([big + 1, small + 1])
	k -= 1
arr.sort()
print(arr[-1] - arr[0], len(res))
for i in res:
	print(*i)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))[:n]
g = []
f = []
cnt = 0
while max(l) - min(l) > 1:
	cnt += 1
	if cnt > m:
		cnt -= 1
		break
	b = max(l)
	c = min(l)
	g.append(l.index(b) + 1)
	f.append(l.index(c) + 1)
	l[l.index(b)] -= 1
	l[l.index(c)] += 1
print(max(l) - min(l), cnt)
for i in range(cnt):
	print(g[i], f[i])


def mi(a):
	m = a[0]
	mi = 0
	for i in range(len(a)):
		if a[i] < m:
			m = a[i]
			mi = i
	return mi

def ma(a):
	m = a[0]
	mi = 0
	for i in range(len(a)):
		if a[i] > m:
			m = a[i]
			mi = i
	return mi
(n, k) = map(int, input().split())
towers = list(map(int, input().split()))
rez = []
counter = 0
for i in range(k):
	maxx = ma(towers)
	minn = mi(towers)
	if maxx == minn or towers[maxx] - towers[minn] == 1:
		break
	towers[maxx] -= 1
	towers[minn] += 1
	rez.append([maxx, minn])
	counter += 1
print(max(towers) - min(towers), counter)
for a in rez:
	print(a[0] + 1, a[1] + 1)


from sys import stdin
import math
(n, k) = map(int, stdin.readline().rstrip().split(' '))
l = list(map(int, stdin.readline().rstrip().split(' ')))
r = []
for i in range(k):
	(mi, ma) = (min(l), max(l))
	a = l.index(mi)
	b = l.index(ma)
	if a == b:
		continue
	l[a] = l[a] + 1
	l[b] -= 1
	r.append([b + 1, a + 1])
print(max(l) - min(l), len(r))
for i in range(len(r)):
	print(*r[i])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(gap, res) = (10000, [])
while 1:
	(i, j) = (f(range(n), key=l.__getitem__) for f in (min, max))
	if gap > l[j] - l[i]:
		gap = l[j] - l[i]
		top = len(res)
		if gap < 2:
			break
	if len(res) == k:
		break
	l[i] += 1
	l[j] -= 1
	res.append(' '.join((str(j + 1), str(i + 1))))
print(max(l) - min(l), top)
print('\n'.join(res[:top]))


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
res = []
for i in range(k):
	mx = arr.index(max(arr))
	mn = arr.index(min(arr))
	if mx != mn:
		arr[mx] -= 1
		arr[mn] += 1
		res.append([mx + 1, mn + 1])
print(str(max(arr) - min(arr)) + ' ' + str(len(res)))
for i in res:
	print(*i)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(ele, end='\n')
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ct = 0
moves = []
for i in range(k):
	ma = a.index(max(a))
	mi = a.index(min(a))
	if a[ma] - a[mi] > 1 and ma != mi:
		a[ma] -= 1
		a[mi] += 1
		moves.append([ma + 1, mi + 1])
	else:
		break
	ct += 1
print(max(a) - min(a), ct)
for i in moves:
	print(i[0], i[1])
endtime = time.time()


def main():
	(n, k) = map(int, input().split())
	towers = list(map(int, input().split()))
	min_index = towers.index(min(towers))
	max_index = towers.index(max(towers))
	dif = towers[max_index] - towers[min_index]
	cant = 0
	operations = []
	while k > 0 and dif > 0:
		if min_index == max_index:
			break
		towers[max_index] -= 1
		towers[min_index] += 1
		operations.append('{0} {1}'.format(max_index + 1, min_index + 1))
		cant += 1
		min_index = towers.index(min(towers))
		max_index = towers.index(max(towers))
		dif = towers[max_index] - towers[min_index]
		k -= 1
	print('{0} {1}'.format(dif, cant))
	for i in operations:
		print(i)
main()


(n, k) = map(int, input().split())
bzz = []
cnt = 0
A = list(map(int, input().split()))
for i in range(k):
	if max(A) - min(A) != 0:
		(i1, i2) = (0, 0)
		(ma, mi) = (0, 10 ** 9)
		for i in range(n):
			if A[i] > ma:
				ma = A[i]
				i1 = i
			if A[i] < mi:
				mi = A[i]
				i2 = i
		bzz.append([i1 + 1, i2 + 1])
		A[i1] -= 1
		A[i2] += 1
		cnt += 1
print(max(A) - min(A), cnt)
for i in bzz:
	print(*i)


import math
import random
import itertools
import collections
import sys
import time
import fractions
import os
import functools
import bisect

def timer(f):

	def tmp(*args, **kwargs):
		t = time.time()
		res = f(*args, **kwargs)
		print('Время выполнения функции: %f' % (time.time() - t))
		return res
	return tmp

def contains(l, elem):
	index = bisect.bisect_left(l, elem)
	if index < len(l):
		return l[index] == elem
	return False
(n, k) = map(int, input().split(' '))
array = list(map(int, input().split(' ')))
actions = []
Nst = []
Nst.append(max(array) - min(array))
for i in range(k):
	maxIndex = 0
	minIndex = 0
	mx = max(array)
	mn = min(array)
	for i in range(len(array)):
		if array[i] == mx:
			maxIndex = i
		if array[i] == mn:
			minIndex = i
	if mx == mn:
		break
	else:
		actions.append([maxIndex, minIndex])
		array[maxIndex] -= 1
		array[minIndex] += 1
	Nst.append(max(array) - min(array))
maxN = max(array) - min(array)
j = 0
for q in range(len(Nst)):
	if Nst[q] == maxN:
		j = q
		break
print(maxN, j)
for i in range(j):
	print(actions[i][0] + 1, actions[i][1] + 1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	a[i] = [a[i], i + 1]
res = []
i = 0
if n > 1:
	for i in range(k):
		a.sort(reverse=True)
		if a[0][0] - 1 > a[-1][0]:
			res.append([a[0][1], a[-1][1]])
			a[0][0] -= 1
			a[-1][0] += 1
		else:
			i -= 1
			break
	a.sort(reverse=True)
	print(a[0][0] - a[-1][0], i + 1)
	for i in res:
		print(i[0], i[1])
else:
	print(0, 0)


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr1 = []
	for i in range(n):
		arr1.append([arr[i], i])
	arr = arr1[:]
	ans = []
	arr.sort()
	min_val = arr[0][0]
	max_val = arr[-1][0]
	while max_val > min_val and k > 0:
		arr[0][0] += 1
		arr[-1][0] -= 1
		ans.append((arr[-1][1] + 1, arr[0][1] + 1))
		arr.sort()
		min_val = arr[0][0]
		max_val = arr[-1][0]
		k -= 1
	print(max_val - min_val, len(ans))
	for i in ans:
		print(i[0], i[1])
main()


(n, k) = map(int, input().split())
p = k
a = list(map(int, input().split()))
c = list()
while k > 0 and max(a) - min(a) > 1:
	c.append(a.index(max(a)) + 1)
	c.append(a.index(min(a)) + 1)
	a[a.index(max(a))] -= 1
	a[a.index(min(a))] += 1
	k -= 1
print(max(a) - min(a), p - k)
i = 0
while len(c) > i:
	print(c[i], c[i + 1])
	i += 2


from sys import stdin, stdout
outputs = []
(n, m) = (int(num) for num in stdin.readline().strip().split())
arr = [int(num) for num in stdin.readline().strip().split()]
for i in range(n):
	arr[i] = [arr[i], i + 1]
arr = sorted(arr, key=lambda t: t[0])
res = []
diff = arr[-1][0] - arr[0][0]
while True and m > 0:
	if diff == 0:
		break
	else:
		(i, j) = (0, n - 1)
		res.append(f'{arr[-1][1]} {arr[0][1]}')
		arr[0][0] += 1
		arr[-1][0] -= 1
		arr = sorted(arr, key=lambda t: t[0])
	m -= 1
	diff = arr[-1][0] - arr[0][0]
stdout.write(f'{diff} {len(res)}\n')
stdout.write('\n'.join(res))


import sys
tow = [int(x) for x in sys.stdin.readline().split()]
initalSteps = tow[1]
towData = [int(x) for x in sys.stdin.readline().split()]
tower = [None] * len(towData)
for idx in range(0, len(towData)):
	tower[idx] = [idx + 1, towData[idx]]
tower = sorted(tower, key=lambda x: x[1])
result = ''
while tow[1] > 0:
	if tower[0][1] >= tower[tow[0] - 1][1] - 1:
		break
	tower[0][1] += 1
	tower[tow[0] - 1][1] -= 1
	result += str(tower[tow[0] - 1][0]) + ' ' + str(tower[0][0]) + '\n'
	idx = 0
	while tower[idx][1] > tower[idx + 1][1]:
		temp = tower[idx + 1]
		tower[idx + 1] = tower[idx]
		tower[idx] = temp
		idx += 1
	idx = tow[0] - 1
	while tower[idx][1] < tower[idx - 1][1]:
		temp = tower[idx - 1]
		tower[idx - 1] = tower[idx]
		tower[idx] = temp
		idx -= 1
	tow[1] -= 1
print(tower[tow[0] - 1][1] - tower[0][1], initalSteps - tow[1])
print(result)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, k) = map(int, input().split(' '))
	b = list(map(int, input().split(' ')))
	ans = []
	a = []
	for x in range(n):
		a.append([b[x], x + 1])
	while k > 0:
		a.sort()
		if a[0][0] == a[-1][0]:
			break
		a[0][0] += 1
		a[-1][0] -= 1
		ans.append([a[-1][1], a[0][1]])
		k -= 1
	a.sort()
	print(a[-1][0] - a[0][0], len(ans))
	for x in ans:
		print(*x)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = input().split()
n = int(n)
k = int(k)
a = [int(i) for i in input().split()]
thres = round(sum(a) / n)
pos = []
early = False
for i in range(k):
	low = a[0]
	l_pos = 0
	high = a[0]
	h_pos = 0
	for j in range(1, n):
		if a[j] > high:
			high = a[j]
			h_pos = j
		elif a[j] < low:
			low = a[j]
			l_pos = j
	if low >= thres or high <= thres:
		early = True
		break
	else:
		a[l_pos] += 1
		a[h_pos] -= 1
		pos.append([h_pos + 1, l_pos + 1])
if early:
	i -= 1
print(max(a) - min(a), i + 1)
for i in range(len(pos)):
	print(pos[i][0], pos[i][1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = ''
c = 0
best = [max(a) - min(a), c, '']
if n > 1:
	for pog in range(k):
		m = 0
		i = 0
		mp = 100000000000000000
		ip = 0
		m = max(a)
		i = a.index(m)
		mp = min(a)
		ip = a.index(mp)
		if m != mp:
			a[i] -= 1
			a[ip] += 1
			s += str(i + 1) + ' ' + str(ip + 1) + '\n'
			c += 1
		else:
			break
		if max(a) - min(a) < best[0]:
			best[0] = max(a) - min(a)
			best[1] = c
			best[2] = s
print(best[0], best[1])
if len(best[2]):
	print(best[2], end='')


import sys

def read(line):
	return [int(c) for c in line.strip().split()]

def main():
	test = sys.stdin.readlines()
	(n, k) = read(test[0])
	towers = read(test[1])
	towers_max = 10001
	min_k = 0
	ops = []
	prev_diff = max(towers) - min(towers)
	min_diff = prev_diff
	for it in range(1, k + 1):
		(mx, mx_i) = (-1, -1)
		(mn, mn_i) = (towers_max, -1)
		for (j, hj) in enumerate(towers):
			if hj < mn:
				(mn, mn_i) = (hj, j)
			if hj > mx:
				(mx, mx_i) = (hj, j)
		towers[mx_i] -= 1
		towers[mn_i] += 1
		diff = max(towers) - min(towers)
		if diff < min_diff:
			min_diff = diff
			min_k = it
		if diff <= prev_diff:
			ops.append((mx_i + 1, mn_i + 1))
			prev_diff = diff
		else:
			break
	print(min_diff, min_k)
	for i in range(min_k):
		print(*ops[i])
main()


(n, k) = map(int, input().split())
heights = []
total = 0
i = 1
for item in map(int, input().split()):
	heights.append([item, i])
	total += item
	i += 1
heights.sort()
middle = total // n
if total % n != 0:
	middle += 1
most_h = heights[n - 1][0]
min_h = heights[0][0]
up_ind = n - 1
down_ind = 0
level_down = heights[down_ind][0]
level_up = heights[up_ind][0]
i = 0
action_list = []
while i < k:
	if heights[down_ind][0] < middle and heights[up_ind][0] > middle:
		if heights[down_ind][0] < heights[0][0] or down_ind == 0:
			heights[down_ind][0] += 1
			action_list.append([heights[up_ind][1], heights[down_ind][1]])
			if heights[up_ind][0] > heights[n - 1][0] or up_ind == n - 1:
				heights[up_ind][0] -= 1
				if heights[up_ind][0] < heights[up_ind - 1][0]:
					up_ind -= 1
				elif heights[up_ind][0] == heights[n - 1][0]:
					up_ind = n - 1
			else:
				up_ind = n - 1
			if heights[down_ind][0] > heights[down_ind + 1][0]:
				down_ind += 1
			elif heights[down_ind][0] == heights[0][0]:
				down_ind = 0
		else:
			down_ind = 0
	elif heights[up_ind][0] - heights[down_ind][0] > 1:
		if heights[up_ind][0] == middle:
			middle -= 1
		elif heights[down_ind][0] == middle:
			middle += 1
	i += 1
print(heights[up_ind][0] - heights[down_ind][0], len(action_list))
for action in action_list:
	print(*action)


from sys import stdin
from collections import deque
import sys
from copy import deepcopy
import math
(n, k) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
s = sum(arr)
min_cap = s // n
max_cap = math.ceil(s / n)
for i in range(n):
	arr[i] = [i, arr[i]]
arr = sorted(arr, key=lambda x: x[1])
i = 0
i = 0
j = n - 1
ans = []
count = 0
while k > 0:
	if arr[0][1] < arr[-1][1]:
		ans.append([arr[-1][0] + 1, arr[0][0] + 1])
		arr[0][1] += 1
		arr[-1][1] -= 1
		k -= 1
		count += 1
	else:
		break
	arr = sorted(arr, key=lambda x: x[1])
arr = sorted(arr, key=lambda x: x[1])
print(abs(arr[0][1] - arr[-1][1]), count)
for i in ans:
	print(*i)


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
position = [i for i in range(1, n + 1)]
step = 0
result = []
for i in range(k):
	new_data = sorted(data)
	n_position = [x for (_, x) in sorted(zip(data, position))]
	if max(new_data) - min(new_data) > 1:
		new_data[0] += 1
		new_data[-1] -= 1
		data = new_data
		position = n_position
		result.append(n_position[-1])
		result.append(n_position[0])
		step = step + 1
	else:
		break
print(max(new_data) - min(new_data), step)
for i in range(0, step * 2 - 1, 2):
	print(result[i], result[i + 1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = list()
cnt = 0
while cnt < k:
	i = a.index(max(a))
	j = a.index(min(a))
	if i == j:
		break
	ans.append((i + 1, j + 1))
	a[i] -= 1
	a[j] += 1
	cnt += 1
stability = max(a) - min(a)
print(stability, cnt)
for (i, j) in ans:
	print(i, j)


(n, k) = map(int, input().split())
t = list(map(int, input().split()))
moves = []
best = 10000
bestl = 0
for l in range(k + 1):
	imin = min(range(len(t)), key=lambda i: t[i])
	imax = max(range(len(t)), key=lambda i: t[i])
	if best > t[imax] - t[imin]:
		best = t[imax] - t[imin]
		bestl = l
	if t[imin] == t[imax]:
		break
	moves.append((imax, imin))
	t[imax] -= 1
	t[imin] += 1
print(best, bestl)
for i in range(bestl):
	(x, y) = moves[i]
	print(x + 1, y + 1)


def minmax(a, n):
	(mn, mx, idx) = (0, 0, 0)
	for idx in range(1, n):
		if a[idx] > a[mx]:
			mx = idx
		if a[idx] < a[mn]:
			mn = idx
	return [mx + 1, mn + 1]
[n, k] = list(map(int, input().split()))
a = list(map(int, input().split()))
moves = []
oper = 0
while oper < k:
	loc = minmax(a, n)
	(mx, mn) = (a[loc[0] - 1], a[loc[1] - 1])
	if mx == mn:
		break
	moves.append(loc)
	a[loc[0] - 1] -= 1
	a[loc[1] - 1] += 1
	oper += 1
print(max(a) - min(a), oper)
for move in moves:
	print(move[0], move[1])


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
x = len(lst)
for i in range(x):
	lst[i] = [lst[i], i]
orig = k
temp = 0
ans = []
while k > 0:
	k -= 1
	lst.sort()
	if lst[n - 1][0] - lst[0][0] > 1:
		lst[n - 1][0] -= 1
		lst[0][0] += 1
		ans.append([lst[n - 1][1], lst[0][1]])
	else:
		temp += 1
lst.sort()
k += temp
print(lst[n - 1][0] - lst[0][0], orig - k)
for i in ans:
	print(i[0] + 1, i[1] + 1)


(a, b) = map(int, input().split(' '))
towers = list(map(int, input().split(' ')))
tow2 = [[towers[i], i + 1] for i in range(len(towers))]
tot = sum(towers)
should = tot // a
num1 = (should + 1) * a - tot
num2 = a - num1
ideal = num1 * [should] + num2 * [should + 1]
ct = 1
x = []
while ct <= b:
	tow2.sort(key=lambda x: x[0])
	if [i[0] for i in tow2] == ideal:
		break
	else:
		x.append([tow2[-1][1], tow2[0][1]])
		tow2[0][0] += 1
		tow2[-1][0] -= 1
	ct += 1
tows = [x[0] for x in tow2]
print(max(tows) - min(tows), ct - 1)
for i in x:
	print(i[0], i[1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ct = 0
moves = []
for i in range(k):
	ma = a.index(max(a))
	mi = a.index(min(a))
	if a[ma] - a[mi] > 1 and ma != mi:
		a[ma] -= 1
		a[mi] += 1
		moves.append([ma + 1, mi + 1])
	else:
		break
	ct += 1
print(max(a) - min(a), ct)
for i in moves:
	print(i[0], i[1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
l = []
r = []
f = True
for h in range(k):
	mi = a[0]
	ma = a[0]
	ai = 0
	aj = 0
	for i in range(len(a)):
		if a[i] < mi:
			mi = a[i]
			ai = i
		if a[i] > ma:
			ma = a[i]
			aj = i
	if ma - mi <= 1:
		mi = a[0]
		ma = a[0]
		for i in range(len(a)):
			if a[i] < mi:
				mi = a[i]
			if a[i] > ma:
				ma = a[i]
		print(ma - mi, ans)
		for i in range(len(l)):
			print(l[i], r[i])
		f = False
		break
	else:
		a[ai] += 1
		a[aj] -= 1
		ans += 1
	l.append(aj + 1)
	r.append(ai + 1)
if f == True:
	mi = a[0]
	ma = a[0]
	for i in range(len(a)):
		if a[i] < mi:
			mi = a[i]
		if a[i] > ma:
			ma = a[i]
	print(ma - mi, ans)
	for i in range(len(l)):
		print(l[i], r[i])


from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
l = list(map(int, input().split()))[:n]
g = []
f = []
cnt = 0
while max(l) - min(l) > 1:
	cnt += 1
	if cnt > m:
		cnt -= 1
		break
	b = max(l)
	c = min(l)
	g.append(l.index(b) + 1)
	f.append(l.index(c) + 1)
	l[l.index(b)] -= 1
	l[l.index(c)] += 1
print(max(l) - min(l), cnt)
for i in range(cnt):
	print(g[i], f[i])


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
diff = []
ops = []
for i in range(k):
	x = arr.index(max(arr))
	y = arr.index(min(arr))
	if i == 0 and max(arr) - min(arr) == 0:
		diff.append(0)
		ops.append(None)
	else:
		arr[x] += -1
		arr[y] += 1
		ops.append((x + 1, y + 1))
		diff.append(max(arr) - min(arr))
	if max(arr) - min(arr) == 0:
		break
if diff[0] == 0 and ops[0] == None:
	print(0, 0)
else:
	fin_ind = diff.index(min(diff))
	print(diff[fin_ind], fin_ind + 1)
	for i in range(fin_ind + 1):
		print(ops[i][0], ops[i][1])


(n, k) = map(int, input().split())
arr = [0] * n
l = 1
for i in list(map(int, input().split())):
	arr[l - 1] = [i, str(l)]
	l += 1
arr.sort()
ans = []
m = 10 ** 5
for i in range(k):
	if arr[-1][0] - arr[0][0] <= 1 or arr[-1][0] - arr[0][0] > m:
		break
	m = arr[-1][0] - arr[0][0]
	arr[0][0] += 1
	arr[-1][0] -= 1
	ans.append(arr[-1][1] + ' ' + arr[0][1])
	if arr[0][0] > arr[1][0]:
		j = 1
		while j < n and arr[0][0] > arr[j][0]:
			j += 1
		(arr[0], arr[j - 1]) = (arr[j - 1], arr[0])
	if arr[-1][0] < arr[-2][0]:
		j = -2
		while j >= -n and arr[-1][0] < arr[j][0]:
			j -= 1
		(arr[-1], arr[j + 1]) = (arr[j + 1], arr[-1])
else:
	i += 1
print(abs(arr[-1][0] - arr[0][0]), i)
if len(ans) != 0:
	print(*ans, sep='\n')


(n, k) = map(int, input().split())
towers = list(map(int, input().split()))
stow = sorted([[towers[i], i] for i in range(0, n)], key=lambda k: k[0])
operations = []
for i in range(0, k):
	stow = sorted(stow, key=lambda k: k[0])
	if stow[n - 1][0] <= stow[0][0] + 1:
		break
	stow[n - 1][0] -= 1
	stow[0][0] += 1
	operations.append([stow[n - 1][1] + 1, stow[0][1] + 1])
stow = sorted(stow, key=lambda k: k[0])
max_ins = stow[n - 1][0] - stow[0][0]
print(max_ins, len(operations))
for op in operations:
	print(*op)


import sys
input = sys.stdin.readline

def multi_input():
	return map(int, input().split())

def array_print(arr):
	print(' '.join(map(str, arr)))
(n, k) = multi_input()
a = list(multi_input())
m = 0
ans = []
diff = sys.maxsize
while k > 0 and max(a) != min(a):
	max1 = a.index(max(a))
	min1 = a.index(min(a))
	diff = max(a) - min(a)
	if diff != 1:
		int_min = min1
		a[max1] -= 1
		a[min1] += 1
		ans.append([max1 + 1, min1 + 1])
		k -= 1
		m += 1
	else:
		break
print(max(a) - min(a), m)
for i in range(m):
	array_print(ans[i])


(n, k) = map(int, input().split())
kb = k
a = [[i + 1, e] for (i, e) in enumerate(map(int, input().split()))]
ans = []
a = sorted(a, key=lambda x: x[1], reverse=True)
while k > 0:
	if a[0][1] - a[-1][1] > 1:
		ans.append([a[0][0], a[-1][0]])
		a[0][1] -= 1
		a[-1][1] += 1
		a = sorted(a, key=lambda x: x[1], reverse=True)
		k -= 1
	else:
		break
print(a[0][1] - a[-1][1], kb - k)
for e in ans:
	print(e[0], e[1])


from math import *
from collections import *
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
	l[i] = [l[i], i + 1]
ans = []
for i in range(k):
	l.sort()
	if l[-1][0] == l[0][0]:
		print(0, i)
		for i in ans:
			print(i[0], i[1])
		break
	l[-1][0] -= 1
	l[0][0] += 1
	ans.append([l[-1][1], l[0][1]])
else:
	l.sort()
	print(l[-1][0] - l[0][0], k)
	for i in ans:
		print(i[0], i[1])


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
ls = []
c = 0
for i in range(x):
	ma = max(l)
	mi = min(l)
	if ma - mi > 1:
		mai = l.index(ma)
		mii = l.index(mi)
		l[mai] = l[mai] - 1
		l[mii] = l[mii] + 1
		ls.append([mai + 1, mii + 1])
		c = c + 1
	else:
		break
q = max(l)
w = min(l)
print(q - w, c)
for e in ls:
	print(*e)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(ans, rest) = ([], [])
while k > 0:
	maxa = max(a)
	mina = min(a)
	res = maxa - mina
	if res <= 1:
		break
	maxi = a.index(maxa)
	mini = a.index(mina)
	a[maxi] -= 1
	a[mini] += 1
	ans.append(maxi + 1)
	rest.append(mini + 1)
	k -= 1
print(max(a) - min(a), len(ans))
for i in range(len(ans)):
	print(ans[i], rest[i])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ret = []
for _ in range(k):
	(minI, maxI) = (a.index(min(a)), a.index(max(a)))
	if a[maxI] - a[minI] <= 1:
		break
	a[maxI] -= 1
	a[minI] += 1
	ret.append('%d %d' % (maxI + 1, minI + 1))
print('%d %d\n%s' % (max(a) - min(a), len(ret), '\n'.join(ret)))


(towers, op) = map(int, input().split())
heights = list(map(int, input().split()))
opDescription = []
for i in range(op):
	maxIndex = heights.index(max(heights))
	minIndex = heights.index(min(heights))
	if minIndex != maxIndex:
		heights[maxIndex] -= 1
		heights[minIndex] += 1
		opDescription.append([maxIndex + 1, minIndex + 1])
print(max(heights) - min(heights), len(opDescription))
for j in opDescription:
	print(' '.join(map(str, j)))


(n, k) = map(int, input().split())
heights = list(map(int, input().split()))
stabilities = [max(heights) - min(heights)]
pos = [(0, 0)]
for i in range(k):
	higher = heights.index(max(heights))
	lower = heights.index(min(heights))
	heights[higher] -= 1
	heights[lower] += 1
	stabilities.append(max(heights) - min(heights))
	pos.append((higher + 1, lower + 1))
smallest = min(stabilities)
operations = stabilities.index(smallest)
print(smallest, operations)
for i in range(operations):
	print(*pos[i + 1])


(n, k) = map(int, input().split())
(a, risp) = ([], [])
a = list(map(int, input().split()))
s = max(a) - min(a)
m = 0
if s < 2:
	print(s, 0)
else:
	for x in range(k):
		maxi = max(a)
		IndMaxi = a.index(maxi)
		mini = min(a)
		IndMini = a.index(mini)
		a[IndMaxi] -= 1
		a[IndMini] += 1
		s = max(a) - min(a)
		m += 1
		risp.append([IndMaxi + 1, IndMini + 1])
		if s == 0:
			break
	print(s, m)
	for x in range(len(risp)):
		print(*risp[x])


(n, m) = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n):
	a.append([b[i], i + 1])
(i, count) = (0, 0)
c = []
while i < m:
	a.sort()
	if a[0][0] != a[-1][0] and a[0][0] + 1 != a[-1][0]:
		a[0][0] += 1
		a[-1][0] -= 1
		c.append([a[-1][1], a[0][1]])
		a.sort()
		count += 1
	elif a[0][0] == a[-1][0] or a[0][0] + 1 == a[-1][0]:
		break
	i += 1
print(a[-1][0] - a[0][0], count)
for i in range(count):
	print(c[i][0], c[i][1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
num_position = [[el, index] for (index, el) in enumerate(l)]
current_unstability = abs(max(num_position)[0] - min(num_position)[0])
min_unstability = 10 * 5
res = []
nb_step = 0
while k > 0:
	(index_max, index_min) = (max(num_position)[1], min(num_position)[1])
	if num_position[index_max][0] - num_position[index_min][0] < 2:
		break
	num_position[index_max][0] -= 1
	num_position[index_min][0] += 1
	current_unstability = abs(num_position[index_max][0] - num_position[index_min][0])
	res.append((index_max + 1, index_min + 1))
	min_unstability = min(min_unstability, current_unstability)
	nb_step += 1
	k -= 1
print(abs(max(num_position)[0] - min(num_position)[0]), nb_step)
for e in res:
	print(e[0], e[1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
for i in range(n):
	ans.append([l[i], i + 1])
ans.sort(key=lambda x: (x[0], x[1]))
s = 0
fns = []
while s != k:
	diff = ans[-1][0] - ans[0][0]
	if diff == 0:
		break
	s += 1
	ans[-1][0] -= 1
	ans[0][0] += 1
	fns.append([ans[-1][1], ans[0][1]])
	if diff == 0:
		break
	ans.sort(key=lambda x: (x[0], x[1]))
print(ans[-1][0] - ans[0][0], len(fns))
for i in fns:
	print(*i)


(tower, move) = map(int, input().split())
height = list(map(int, input().split()))
m = max(height)
n = min(height)
difference = m - n
indexMax = -1
indexMin = -1
for i in range(tower):
	if m == height[i]:
		indexMax = i
	if n == height[i]:
		indexMin = i
chances = []
counter = 0
while move != 0 and difference != 0 and (difference != 1):
	move -= 1
	counter += 1
	height[indexMax] -= 1
	height[indexMin] += 1
	chances.append(indexMax + 1)
	chances.append(indexMin + 1)
	m = max(height)
	n = min(height)
	indexMax = -1
	indexMin = -1
	for i in range(tower):
		if m == height[i]:
			indexMax = i
		if n == height[i]:
			indexMin = i
	difference = m - n
print(difference, counter)
for i in range(0, 2 * counter, 2):
	print(chances[i], chances[i + 1])


inpt = input().split(' ')
n = int(inpt[0])
k = int(inpt[1])
i_lst = []
j_lst = []
m = 0
inpt = input().split(' ')
for i in range(len(inpt)):
	inpt[i] = int(inpt[i])
for i in range(k):
	mn = min(inpt)
	mx = max(inpt)
	if mn != mx:
		i_mn = inpt.index(mn)
		i_mx = inpt.index(mx)
		inpt[i_mn] += 1
		inpt[i_mx] -= 1
		i_lst.append(i_mx)
		j_lst.append(i_mn)
		m += 1
	else:
		break
instblity = max(inpt) - min(inpt)
print(str(instblity) + ' ' + str(m))
for i in range(len(i_lst)):
	print(str(i_lst[i] + 1) + ' ' + str(j_lst[i] + 1))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
val = max(h) - min(h)
step = 0
move = []
for t in range(k):
	i = h.index(max(h))
	j = h.index(min(h))
	h[i] -= 1
	h[j] += 1
	move.append((i + 1, j + 1))
	newval = max(h) - min(h)
	if val > newval:
		step = t + 1
		val = newval
print(val, step)
for i in range(step):
	(ii, jj) = move[i]
	print(ii, jj)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
for i in range(k):
	(minn, maxn) = (min(l), max(l))
	(minindex, maxindex) = (l.index(minn), l.index(maxn))
	if minn != maxn:
		ans.append((maxindex + 1, minindex + 1))
		l[minindex] += 1
		l[maxindex] -= 1
print(max(l) - min(l), len(ans))
for i in ans:
	print(*i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = [[a[x], x] for x in range(n)]
a.sort()
ans = []
while k > 0 and a[-1][0] != a[0][0]:
	a[-1][0] -= 1
	a[0][0] += 1
	k -= 1
	ans.append((a[-1][1] + 1, a[0][1] + 1))
	a.sort()
print(a[-1][0] - a[0][0], len(ans))
for x in ans:
	print(*x)


(n, k) = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
dd = dict()
for i in range(n):
	if a[i] in dd:
		dd[a[i]].append(i)
	else:
		dd[a[i]] = [i]
b = sorted(set(a))
mm = list(range(k + 1))
i = 0
move = [[0, 0]] * (k + 1)
while i <= k - 1 and b[-1] - b[0] > 1:
	i = i + 1
	move[i][0] = dd[b[-1]].pop()
	move[i][1] = dd[b[0]].pop()
	mm[i] = str(move[i][0] + 1) + ' ' + str(move[i][1] + 1)
	temp = b[-1] - 1
	temp1 = temp
	if temp in dd:
		dd[temp].append(move[i][0])
	else:
		dd[temp] = [move[i][0]]
	if dd[b[-1]] == []:
		b[-1] = temp
	temp = b[0] + 1
	temp2 = temp
	if temp in dd:
		dd[temp].append(move[i][1])
	else:
		dd[temp] = [move[i][1]]
	if dd[b[0]] == []:
		b[0] = temp
	b.append(temp1)
	b.append(temp2)
	b = sorted(set(b))
print(b[-1] - b[0], i)
for j in range(1, i + 1):
	print(mm[j])


import sys
input = sys.stdin.readline

def update_front(n, arr):
	for i in range(n - 1):
		if arr[i][0] > arr[i + 1][0]:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		else:
			break

def update_back(n, arr):
	for i in reversed(range(n - 1)):
		if arr[i][0] > arr[i + 1][0]:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		else:
			break

def get_min(score):
	mn = float('inf')
	index = None
	for (i, s) in enumerate(score):
		if s < mn:
			index = i
			mn = s
	return index
(n, k) = map(int, input().split())
arr = [[int(v), i] for (i, v) in enumerate(input().split(), start=1)]
arr.sort()
score = []
ops = []
pre = arr[-1][0] - arr[0][0]
for _ in range(k):
	arr[-1][0] -= 1
	arr[0][0] += 1
	ops.append((arr[-1][1], arr[0][1]))
	update_front(n, arr)
	update_back(n, arr)
	score.append(arr[-1][0] - arr[0][0])
j = get_min(score)
if score[j] < pre:
	print(score[j], j + 1)
	for i in range(j + 1):
		print(*ops[i])
else:
	print(pre, 0)


import math
import sys
import collections
import bisect
import time

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for tc in range(1):
	(n, k) = get_ints()
	arr = get_list()
	operation = []
	while k > 0:
		maxim_val = 0
		pos = 0
		for i in range(n):
			if arr[i] > maxim_val:
				maxim_val = arr[i]
				pos = i
		minim = 10 ** 10
		minim_pos = 0
		for i in range(n):
			if arr[i] < minim:
				minim = arr[i]
				minim_pos = i
		if maxim_val == minim or maxim_val - minim == 1:
			break
		operation.append([pos + 1, minim_pos + 1])
		arr[pos] -= 1
		arr[minim_pos] += 1
		k -= 1
	print(max(arr) - min(arr), len(operation))
	for i in operation:
		print(*i)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = []
while m != 0:
	mx = l.index(max(l))
	mi = l.index(min(l))
	if mi != mx:
		l[mi] += 1
		l[mx] -= 1
		ans.append((mx + 1, mi + 1))
	m -= 1
print(max(l) - min(l), len(ans))
for i in range(len(ans)):
	print(ans[i][0], ans[i][1])


(n, k) = map(int, input().split())
tab = [0 for loop in range(n)]
t = input().split()
for i in range(n):
	tab[i] = int(t[i])

def max():
	global n
	y = 0
	j = 0
	for i in range(n):
		if tab[i] > y:
			y = tab[i]
			j = i
	return j

def min():
	global n
	x = 100000
	j = 0
	for i in range(n):
		if tab[i] < x:
			x = tab[i]
			j = i
	return j

def maxv():
	global n
	y = 0
	j = 0
	for i in range(n):
		if tab[i] > y:
			y = tab[i]
			j = i
	return y

def minv():
	global n
	x = 100000
	j = 0
	for i in range(n):
		if tab[i] < x:
			x = tab[i]
			j = i
	return x
liste = [(0, 0) for loop in range(k)]
m = 0
v = maxv() - minv()
for j in range(k):
	a = max()
	b = min()
	tab[a] -= 1
	tab[b] += 1
	liste[j] = (a + 1, b + 1)
	c = maxv() - minv()
	if c < v:
		v = c
		m = j + 1
print(maxv() - minv(), m)
for i in range(m):
	(d, e) = liste[i]
	print(d, e)


def main():
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	result = []
	for times in range(k):
		minimal = min(a)
		maximal = max(a)
		if maximal - minimal <= 1:
			break
		mini = a.index(minimal)
		maxi = a.index(maximal)
		a[mini] += 1
		a[maxi] -= 1
		result.append((maxi + 1, mini + 1))
	print(max(a) - min(a), len(result))
	print('\n'.join((' '.join(map(str, i)) for i in result)))
main()


(n, k) = map(int, input().split())
towers = list(map(int, input().split()))

def get_min_max_indices():
	tmp = towers[0]
	max_index = 0
	min_index = 0
	for i in range(1, len(towers)):
		if towers[i] > towers[max_index]:
			max_index = i
		if towers[i] < towers[min_index]:
			min_index = i
	return (min_index, max_index)
tracks = []
for i in range(k):
	(min_index, max_index) = get_min_max_indices()
	if towers[min_index] == towers[max_index]:
		break
	towers[max_index] -= 1
	towers[min_index] += 1
	tracks.append([max_index + 1, min_index + 1])
(lowest_point, highest_point) = get_min_max_indices()
print(towers[highest_point] - towers[lowest_point], len(tracks))
for record in tracks:
	print(*record)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, k) = ei()
li = ai()
index = []
prev = float('inf')
for i in range(k):
	mx = max(li)
	mn = min(li)
	if mx - mn <= 1:
		break
	mx_idx = li.index(mx)
	mn_index = li.index(mn)
	index.append((mx_idx + 1, mn_index + 1))
	li[mx_idx] -= 1
	li[mn_index] += 1
print(max(li) - min(li), len(index))
for j in index:
	print(*j)


f = list(map(int, input().split()))
heights = list(map(int, input().split()))
num = f[0]
kops = f[1]
minpossible = 0 if sum(heights) % num == 0 else 1
curinstability = max(heights) - min(heights)
opscounter = 0
rem = list()
while curinstability > minpossible and opscounter < kops:
	lowi = heights.index(min(heights))
	highi = heights.index(max(heights))
	heights[lowi] += 1
	heights[highi] -= 1
	rem.append((highi + 1, lowi + 1))
	opscounter += 1
	curinstability = max(heights) - min(heights)
print(max(heights) - min(heights), opscounter)
for vals in rem:
	print(vals[0], vals[1])


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for i in range(n):
	a[i] = [a[i], i]
a.sort()
ans = []
for i in range(k):
	if all((x == a[0] for x in a)):
		break
	l = 0
	r = n - 1
	for i in range(n - 1):
		if a[i][0] < a[i + 1][0]:
			l = i
			break
	for i in range(n - 1, 0, -1):
		if a[i - 1][0] < a[i][0]:
			r = i
			break
	if a[l][0] + 1 >= a[r][0]:
		break
	ans.append(str(a[r][1] + 1) + ' ' + str(a[l][1] + 1))
	a[l][0] += 1
	a[r][0] -= 1
print(max((x[0] for x in a)) - min((x[0] for x in a)), len(ans))
print('\n'.join(ans))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
ans = []
for i in range(k):
	maxi = a.index(max(a))
	mini = a.index(min(a))
	if maxi == mini:
		break
	a[maxi] -= 1
	a[mini] += 1
	ans.append((maxi + 1, mini + 1))
val = max(a) - min(a)
print(val, len(ans))
for (i, j) in ans:
	print(i, j)


def inp(s):
	j = 0
	a = []
	for i in range(len(s)):
		if s[i] == ' ':
			a.append(int(s[j:i]))
			j = i + 1
		if i == len(s) - 1:
			a.append(int(s[j:]))
	return a

def ins(a):
	return max(a) - min(a)
(n, k) = input().split()
k = int(k)
s = input()
a = inp(s)
i = 0
r = []
while i < k and ins(a) > 1:
	mx = max(a)
	mn = min(a)
	p1 = a.index(mx)
	p2 = a.index(mn)
	a[p1] = a[p1] - 1
	a[p2] = a[p2] + 1
	r.append((p1 + 1, p2 + 1))
	i = i + 1
print(ins(a), i)
for i in r:
	print(i[0], i[1])


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
output = []
(instability, moves) = (max(a) - min(a), 0)
while moves < k:
	(high, low) = (max(a), min(a))
	(h, l) = (a.index(max(a)), a.index(min(a)))
	if h == l:
		break
	(a[h], a[l]) = (a[h] - 1, a[l] + 1)
	moves += 1
	output.append((h + 1, l + 1))
	instability = max(a) - min(a)
print(instability, moves)
for p in output:
	print(*(x for x in p))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
count = 0
l1 = []
l2 = []
while count < k:
	x = l.index(max(l))
	y = l.index(min(l))
	if l[x] - l[y] == 1 or l[x] - l[y] == 0:
		break
	l1.append(x + 1)
	l2.append(y + 1)
	l[x] = l[x] - 1
	l[y] = l[y] + 1
	count = count + 1
ans = max(l) - min(l)
print(ans, end=' ')
print(count)
for i in range(count):
	print(l1[i], end=' ')
	print(l2[i])


operations = []
a = input().split(' ')
towers = input().split(' ')
k = int(a[1])
for i in range(len(towers)):
	towers[i] = int(towers[i])

def inst(tset):
	return max(tset) - min(tset)

def fix(towerset):
	proset = []
	for element in towerset:
		proset.append(element)
	b = proset.index(max(proset))
	c = proset.index(min(proset))
	d = inst(proset)
	e = max(proset) - 1
	proset[b] -= 1
	proset[c] += 1
	if proset[c] <= e:
		return [b + 1, c + 1, proset]
	else:
		return 'end'
count = 0
result = None
while result != 'end':
	h = inst(towers)
	g = fix(towers)
	if g == 'end':
		break
	elif count == k:
		break
	else:
		operations.append([g[0], g[1]])
		towers = g[2]
		count += 1
print(inst(towers), count)
for j in range(len(operations)):
	print(operations[j][0], operations[j][1])


class CodeforcesTask479BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []
		self.heights = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]
		self.heights = [int(x) for x in input().split(' ')]

	def process_task(self):
		res = []
		for _ in range(self.n_k[1]):
			from_i = self.heights.index(max(self.heights))
			to_i = self.heights.index(min(self.heights))
			if from_i == to_i:
				break
			self.heights[from_i] -= 1
			self.heights[to_i] += 1
			res.append((from_i + 1, to_i + 1))
		stab = max(self.heights) - min(self.heights)
		ops = '\n'.join((' '.join([str(y) for y in x]) for x in res))
		self.result = f'{stab} {len(res)}\n{ops}'

	def get_result(self):
		return self.result
Solution = CodeforcesTask479BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def main():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	(diff, res) = (10000, [])
	while True:
		i = min(range(n), key=l.__getitem__)
		j = max(range(n), key=l.__getitem__)
		if diff > l[j] - l[i]:
			diff = l[j] - l[i]
			top = len(res)
			if diff < 2:
				break
		if len(res) == k:
			break
		l[i] += 1
		l[j] -= 1
		res.append(' '.join((str(j + 1), str(i + 1))))
	print(max(l) - min(l), top)
	if top:
		print('\n'.join(res[:top]))
main()


(n, k) = map(int, input().split())
(t, o) = ([], [])
for (i, h) in enumerate(map(int, input().split())):
	t.append([h, i + 1])
for i in range(k):
	t.sort()
	if t[0][0] >= t[-1][0] - 1:
		break
	t[0][0] += 1
	t[-1][0] -= 1
	o.append((t[-1][1], t[0][1]))
t.sort()
print(t[-1][0] - t[0][0], len(o))
for oi in o:
	print(oi[0], oi[1])


(n, k) = [int(x) for x in input().split()]
towers = list(map(int, input().split()))
prom = int(sum(towers) / n)
actions = []
while k > 0:
	alto = towers.index(max(towers)) + 1
	bajo = towers.index(min(towers)) + 1
	if alto == bajo:
		break
	towers[alto - 1] -= 1
	towers[bajo - 1] += 1
	actions.append((alto, bajo))
	k -= 1
alto = max(towers)
bajo = min(towers)
print(alto - bajo, len(actions))
for i in actions:
	print(i[0], i[1])


(s, m) = map(int, input().split())
ls = [int(u) for u in input().split()]
ls_copy = ls.copy()
k = 0
operations = []
for _ in range(0, m):
	if max(ls) == min(ls):
		break
	else:
		k += 1
		operations.append([ls.index(max(ls)) + 1, ls.index(min(ls)) + 1])
		ls[ls.index(max(ls))] -= 1
		ls[ls.index(min(ls))] += 1
instab = max(ls) - min(ls)
operations = []
k = 0
for _ in range(0, m):
	if max(ls_copy) - min(ls_copy) == instab:
		break
	else:
		k += 1
		operations.append([ls_copy.index(max(ls_copy)) + 1, ls_copy.index(min(ls_copy)) + 1])
		ls_copy[ls_copy.index(max(ls_copy))] -= 1
		ls_copy[ls_copy.index(min(ls_copy))] += 1
instab = max(ls_copy) - min(ls_copy)
print(instab, k)
for elements in operations:
	print(elements[0], elements[1])


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
for _ in range(k):
	mx = arr.index(max(arr))
	mn = arr.index(min(arr))
	if arr[mx] == arr[mn]:
		break
	arr[mx] -= 1
	arr[mn] += 1
	ans += [(mx + 1, mn + 1)]
print(max(arr) - min(arr), len(ans))
print('\n'.join([str(x[0]) + ' ' + str(x[1]) for x in ans]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
count = 0
a = []
for i in range(k):
	minimum = min(l)
	maximum = max(l)
	if maximum - minimum <= 1:
		break
	u = l.index(minimum)
	v = l.index(maximum)
	l[u] += 1
	l[v] -= 1
	a.append((v + 1, u + 1))
print(max(l) - min(l), len(a))
print('\n'.join((' '.join(map(str, i)) for i in a)))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
op = 0
factor = max(arr) - min(arr)
while factor > 1 and op < k:
	m = arr.index(min(arr))
	M = arr.index(max(arr))
	arr[m] += 1
	arr[M] -= 1
	op += 1
	ans.append([M + 1, m + 1])
	factor = max(arr) - min(arr)
print(factor, op)
for i in ans:
	print(*i)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
oldins = 0
ins = max(x) - min(x)
diff = 0
order = []
while max(x) != min(x) and max(x) != min(x) + 1 and (diff < k):
	a = x.index(min(x))
	b = x.index(max(x))
	order.append([b + 1, a + 1])
	x[x.index(min(x))] += 1
	x[x.index(max(x))] -= 1
	diff += 1
ins = max(x) - min(x)
print(ins, diff)
for i in range(diff):
	print(order[i][0], order[i][1])


v = list(input().split())
n = int(v[0])
k = int(v[1])
v = list((int(x) for x in input().split()))
dol = list()
dolc = 0
s = 0
for i in range(k):
	minv = min(v)
	maxv = max(v)
	minvi = v.index(minv)
	maxvi = v.index(maxv)
	if maxv - minv == 0:
		break
	if maxv - minv == 1:
		if s == 1:
			break
		else:
			s = 1
	v[minvi] += 1
	v[maxvi] -= 1
	dol.append(str(maxvi + 1) + ' ' + str(minvi + 1))
	dolc += 1
if dolc == 0:
	print('0 0')
else:
	print(max(v) - min(v), dolc)
	for i in range(dolc):
		print(dol[i])


import itertools
import math

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	res = []
	for i in range(k):
		if max(a) - min(a) <= 1:
			break
		t = (a.index(max(a)), a.index(min(a)))
		res.append(t)
		a[t[0]] -= 1
		a[t[1]] += 1
	print(max(a) - min(a), len(res))
	for t in res:
		print(t[0] + 1, t[1] + 1)
main()


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
nextli = []
alist = sorted(li)
s = 0
r = max(alist) - min(alist)
while True:
	m = li.index(max(alist))
	p = li.index(min(alist))
	li[m] -= 1
	li[p] += 1
	blist = sorted(li)
	l = max(alist) - min(alist)
	if blist == alist or s >= k or l > r:
		r = l
		break
	else:
		r = l
		nextli.append(m)
		nextli.append(p)
		alist = blist
		s += 1
print(r, s)
i = 0
while True:
	if i >= len(nextli):
		break
	print(nextli[i] + 1, nextli[i + 1] + 1)
	i = i + 2


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	a[i] = [a[i], i]
a.sort()
i = -1
if a[-1][0] - a[0][0] == 1 or a[-1][0] - a[0][0] == 0:
	k = 0
for i in range(k):
	a[-1][0] -= 1
	a[0][0] += 1
	ans += [[a[-1][1] + 1, a[0][1] + 1]]
	if a[0][0] > a[1][0] or a[-1][0] < a[-2][0]:
		a.sort()
	if a[-1][0] - a[0][0] == 1 or a[-1][0] - a[0][0] == 0:
		break
a.sort()
print(a[-1][0] - a[0][0], end=' ')
print(i + 1)
for item in ans:
	print(' '.join(map(str, item)))


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
ans = []
for i in range(k):
	mx = arr.index(max(arr))
	mn = arr.index(min(arr))
	if mx != mn:
		arr[mx] -= 1
		arr[mn] += 1
		ans.append([mx + 1, mn + 1])
print(str(max(arr) - min(arr)) + ' ' + str(len(ans)))
for x in ans:
	print(' '.join(map(str, x)))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(k):
	mi = 10 ** 10
	for j in range(n):
		if a[j] < mi:
			mi = a[j]
			pos_mi = j
	ma = -10 ** 10
	for j in range(n):
		if a[j] > ma:
			ma = a[j]
			pos_ma = j
	if ma <= mi + 1:
		break
	ans.append([pos_ma + 1, pos_mi + 1])
	a[pos_ma] -= 1
	a[pos_mi] += 1
print(max(a) - min(a), len(ans))
for i in range(len(ans)):
	print(*ans[i])


infinity = 10 ** 30

def find_extreme_towers(towers):
	(min_tower, max_tower) = (0, 0)
	for tower in range(len(towers)):
		if towers[tower] < towers[min_tower]:
			min_tower = tower
		if towers[tower] > towers[max_tower]:
			max_tower = tower
	return (min_tower, max_tower)

def compute_instability(towers):
	(min_tower, max_tower) = find_extreme_towers(towers)
	return towers[max_tower] - towers[min_tower]
(nb_towers, nb_operations) = map(int, input().split())
towers = list(map(int, input().split()))
min_instability = compute_instability(towers)
operations = []
nb_operations_min = 0
for operation in range(nb_operations + 1):
	cur_instability = compute_instability(towers)
	if cur_instability < min_instability:
		min_instability = cur_instability
		nb_operations_min = operation
	if operation < nb_operations:
		(min_tower, max_tower) = find_extreme_towers(towers)
		operations.append((max_tower + 1, min_tower + 1))
		towers[min_tower] += 1
		towers[max_tower] -= 1
print(min_instability, nb_operations_min, sep=' ')
for operation in range(nb_operations_min):
	print(operations[operation][0], operations[operation][1], sep=' ')


(n, k) = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
inst = max(t) - min(t)
i = 0
steps = []
while inst > 0 and i < k:
	imax = t.index(max(t))
	imin = t.index(min(t))
	steps.append(imax + 1)
	steps.append(imin + 1)
	t[imax] -= 1
	t[imin] += 1
	inst = max(t) - min(t)
	i += 1
print(inst, i)
for i in range(0, len(steps), 2):
	print(steps[i], steps[i + 1])


(towers, operationsNum) = map(int, input().split())
towersHeights = list(map(int, input().split()))
changes = []
for i in range(operationsNum):
	(minH, maxH) = (min(towersHeights), max(towersHeights))
	instability = max(towersHeights) - min(towersHeights)
	(minindex, maxindex) = (towersHeights.index(minH), towersHeights.index(maxH))
	if instability != 0:
		changes.append(str(maxindex + 1) + ' ' + str(minindex + 1))
		towersHeights[minindex] += 1
		towersHeights[maxindex] -= 1
print(max(towersHeights) - min(towersHeights), len(changes))
for i in changes:
	print(i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(sorted(([val, ind] for (ind, val) in enumerate(a, 1)), reverse=True))
t = 0
li = []
minm = b[0][0] - b[-1][0]
for i in range(k):
	diff = b[0][0] - b[-1][0]
	if diff > 0 and diff <= minm:
		t += 1
		b[0][0] -= 1
		b[-1][0] += 1
		li.append([b[0][1], b[-1][1]])
		first = b[0]
		last = b[-1]
		b.sort(reverse=True)
		if minm == b[0][0] - b[-1][0] and b[0][1] == last[1] and (b[-1][1] == first[1]):
			t -= 1
			li.pop()
			break
		minm = b[0][0] - b[-1][0]
	else:
		break
print(minm, t)
for x in li:
	print(*x)


(a, b) = map(int, input().split())
k1 = []
k2 = []
c = list(map(int, input().split()))
lol = max(c) - min(c)
if a == 1:
	print(0, 0)
else:
	for i in range(b):
		mix = -1
		man = 10000000000000
		for j in range(a):
			if c[j] >= mix:
				mix = c[j]
				p1 = j
			if c[j] < man:
				man = c[j]
				p2 = j
		if mix == man:
			break
		c[p2] += 1
		c[p1] -= 1
		k1.append(p1 + 1)
		k2.append(p2 + 1)
	mix = -1
	man = 10000000000000
	for j in range(a):
		if c[j] >= mix:
			mix = c[j]
		if c[j] < man:
			man = c[j]
	print(mix - man, len(k1))
	for i in range(len(k1)):
		print(k1[i], k2[i])