The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height a_{i} meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n), a_{i} + 1 - a_{i} = k, where k is the number the Queen chose.

Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?


-----Input-----

The first line contains two space-separated integers: n, k (1 ≤ n, k ≤ 1000). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000) — the heights of the trees in the row. 


-----Output-----

In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions. 

If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".

If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.


-----Examples-----
Input
4 1
1 2 1 5

Output
2
+ 3 2
- 4 1

Input
4 1
1 2 3 4

Output
0

Difficulty: MEDIUM

Solutions:
import math

def main():
	(n, k) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	l2 = [l[i] - i * k for i in range(len(l))]
	d = dict()
	m = 0
	mn = 0
	for i in l2:
		if i > 0:
			try:
				d[i] += 1
			except:
				d[i] = 1
			if d[i] > m:
				m = d[i]
				mn = i
	count = 0
	ans = []
	for i in range(len(l2)):
		if l2[i] != mn:
			ans += [('+' if l2[i] < mn else '-') + ' ' + str(i + 1) + ' ' + str(abs(l2[i] - mn))]
			count += 1
	print(count)
	for i in ans:
		print(i)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
arr = [int(z) for z in input().split()]
cap = 1001
potentialfirst = []
ops = []
for pot in range(1, cap):
	cnt = 0
	r = []
	for i in range(n):
		if arr[i] != pot + i * k:
			cnt += 1
		if arr[i] < pot + i * k:
			r.append(['+', str(i + 1), str(abs(arr[i] - (pot + i * k)))])
		elif arr[i] > pot + i * k:
			r.append(['-', str(i + 1), str(abs(arr[i] - (pot + i * k)))])
	potentialfirst.append(cnt)
	ops.append(r)
ind = potentialfirst.index(min(potentialfirst))
print(potentialfirst[ind])
for i in ops[ind]:
	print(' '.join(i))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
tmp = {}
for i in range(n):
	x = a[i] - i * k
	if x > 0:
		tmp[x] = tmp.get(x, 0) + 1
x = max(tmp, key=lambda x: tmp[x])
print(n - tmp[x])
if tmp[x] == n:
	exit(0)
for i in range(n):
	if x + i * k > a[i]:
		print('+', i + 1, x + i * k - a[i])
	elif x + i * k < a[i]:
		print('-', i + 1, a[i] - i * k - x)


(n, k) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
upper_bound = 1
base_height = 1
ans = None
for i in range(len(a)):
	upper_bound = max(upper_bound, a[i] - k * i)
for i in range(1, upper_bound + 1):
	ans_candi = sum((1 for j in range(len(a)) if a[j] - i - k * j))
	if ans == None or ans_candi < ans:
		ans = ans_candi
		base_height = i
print(ans)
for i in range(len(a)):
	diff = a[i] - base_height - i * k
	if diff:
		print('{} {} {}'.format('-' if diff > 0 else '+', i + 1, abs(diff)))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
vis = [False] * n
answer = 0
for i in range(n):
	t = 0
	if not vis[i]:
		for j in range(i, n):
			if not vis[j]:
				temp = a[j] - (j - i) * k
				x = temp - a[i]
				if x == 0:
					t += 1
					vis[j] = True
				if temp <= 0:
					vis[j] = True
	if t > answer:
		answer = t
		poi = i
		val = a[i]
print(n - answer)
if answer != n:
	for i in range(n):
		x = a[i] - val - (i - poi) * k
		if x == 0:
			continue
		elif x > 0:
			print('{} {} {}'.format('-', i + 1, x))
		elif x < 0:
			print('{} {} {}'.format('+', i + 1, -x))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
vis = [False] * n
answer = 0
for i in range(n):
	t = 0
	if not vis[i]:
		for j in range(i, n):
			if not vis[j]:
				temp = a[j] - (j - i) * k
				x = temp - a[i]
				if x == 0:
					t += 1
					vis[j] = True
				if temp <= 0:
					vis[j] = True
	if t > answer:
		answer = t
		poi = i
		val = a[i]
print(n - answer)
if answer != n:
	for i in range(n):
		x = a[i] - val - (i - poi) * k
		if x == 0:
			continue
		elif x > 0:
			print('{} {} {}'.format('-', i + 1, x))
		elif x < 0:
			print('{} {} {}'.format('+', i + 1, -x))


(n, k) = map(int, input().split())
q = list(map(int, input().split()))
a = dict()
for i in range(n):
	a0 = q[i] - k * i
	if a0 > 0:
		if a0 in a:
			a[a0] += 1
		else:
			a[a0] = 1
mx = -1
a0 = -1
for i in a:
	if a[i] > mx:
		mx = a[i]
		a0 = i
print(n - mx)
for i in range(n):
	qw = a0 + k * i
	if q[i] != qw:
		if q[i] > qw:
			print('-', i + 1, q[i] - qw)
		else:
			print('+', i + 1, qw - q[i])


def check_bounds(start):
	return heights[start] - start * k >= 1
(n, k) = map(int, input().split())
heights = list(map(int, input().split()))
seq_start = -1
lon_seq = [0] * n
max_len = 0
cur_seq = [0] * n
cur_len = 0
for (i, a) in enumerate(heights):
	cur_seq = [0] * n
	cur_len = 0
	if check_bounds(i):
		for (j, b) in enumerate(heights):
			if b == a + (j - i) * k:
				cur_seq[j] = 1
				cur_len += 1
		if cur_len > max_len:
			lon_seq = cur_seq
			max_len = cur_len
			seq_start = i
print(n - max_len)
for (i, a) in enumerate(heights):
	if lon_seq[i] != 1:
		diff = a - (heights[seq_start] + (i - seq_start) * k)
		if diff > 0:
			print('{0} {1} {2}'.format('-', i + 1, abs(diff)))
		else:
			print('{0} {1} {2}'.format('+', i + 1, abs(diff)))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
m = 0
index = 0
for i in range(n):
	c = 0
	for j in range(n):
		if l[i] + (j - i) * k <= 0:
			break
		if l[i] + (j - i) * k == l[j]:
			c = c + 1
	if m < c:
		m = c
		index = i
a = 0
print(n - m)
for i in range(n):
	if l[i] != l[index] - (index - i) * k:
		if l[i] < l[index] - k * (index - i):
			print('+', i + 1, l[index] - (index - i) * k - l[i])
		else:
			print('-', i + 1, l[i] - l[index] + k * (index - i))


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		mn = P
		ans = []
		for i in range(1, 1001):
			a = []
			temp = i
			for j in range(n):
				if temp > l[j]:
					a.append(['+', j + 1, temp - l[j]])
				elif temp < l[j]:
					a.append(['-', j + 1, l[j] - temp])
				temp += k
			if len(a) < mn:
				ans = a.copy()
				mn = len(ans)
		print(mn)
		for x in ans:
			print(*x)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


(n, k) = map(int, input().split())
alist = [int(x) for x in input().split()]
minchange = n
mina = 1000
for a in range(1, 1001):
	blist = [x * k + a for x in range(0, n)]
	change = 0
	for i in range(0, n):
		if alist[i] != blist[i]:
			change += 1
		if change >= minchange:
			break
	if change < minchange:
		minchange = change
		mina = a
blist = [x * k + mina for x in range(0, n)]
changelist = []
for i in range(0, n):
	if alist[i] > blist[i]:
		changelist.append('- ' + str(i + 1) + ' ' + str(alist[i] - blist[i]))
	elif alist[i] < blist[i]:
		changelist.append('+ ' + str(i + 1) + ' ' + str(blist[i] - alist[i]))
print(minchange)
if minchange > 0:
	for change in changelist:
		print(change)


a = input()
a = a.split()
a = list(map(int, a))
n = a[0]
k = a[1]
h = input()
h = h.split()
h = list(map(int, h))
c = []

def make(h, x):
	nonlocal k
	r = list(range(x))
	r.reverse()
	counter = 0
	for i in r:
		if h[i + 1] - h[i] != k:
			h[i] = h[i + 1] - k
			counter += 1
	for i in range(x + 1, n):
		if h[i] - h[i - 1] != k:
			h[i] = h[i - 1] + k
			counter += 1
	if min(h) <= 0:
		counter = 1000000
	return counter

def myPrint(h, x):
	nonlocal k
	r = list(range(x))
	r.reverse()
	for i in r:
		if h[i + 1] - h[i] != k:
			if h[i] < h[i + 1] - k:
				print('+', i + 1, h[i + 1] - k - h[i])
			else:
				print('-', i + 1, -(h[i + 1] - k - h[i]))
			h[i] = h[i + 1] - k
	for i in range(x + 1, n):
		if h[i] - h[i - 1] != k:
			if h[i] < h[i - 1] + k:
				print('+', i + 1, h[i - 1] + k - h[i])
			else:
				print('-', i + 1, -(h[i - 1] + k - h[i]))
			h[i] = h[i - 1] + k
	return
for i in range(n):
	c.append(make(h.copy(), i))
m = c.index(min(c))
print(c[m])
myPrint(h, m)


class CodeforcesTask402BSolution:

	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):
		w_k = 1001
		chosen = -1
		for base in range(1, 1001):
			costs = sum([0 if self.heights[x] == base + self.n_k[1] * x else 1 for x in range(self.n_k[0])])
			if costs < w_k:
				chosen = base
				w_k = costs
		operations = []
		for x in range(self.n_k[0]):
			if self.heights[x] != chosen + self.n_k[1] * x:
				diff = chosen + self.n_k[1] * x - self.heights[x]
				sign = '+' if diff > 0 else '-'
				operations.append('{0} {1} {2}'.format(sign, x + 1, abs(diff)))
		self.result = '{0}\n{1}'.format(len(operations), '\n'.join(operations))

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


(n, k) = map(int, input().split())
L = list(map(int, input().split()))
a = min(L)
b = max(L)
ans = 10 ** 10
F = []
for s in range(1, 1001):
	x = 0
	E = []
	for i in range(n):
		if abs(s + i * k - L[i]):
			x += 1
			E.append(i)
	if x < ans:
		ans = x
		F = list(E) + [s]
print(ans)
s = F[-1]
for i in range(ans):
	if L[F[i]] < s + F[i] * k:
		print('+', end=' ')
	else:
		print('-', end=' ')
	print(F[i] + 1, abs(L[F[i]] - (s + F[i] * k)))


(n, k) = map(int, input().split())
z = [int(x) for x in input().split()]
lim = max(z)
ctr = 10000000
minz = []
minz_num = []
for i in range(1, max(z) + 1):
	strt = i
	moves = 0
	for j in range(0, len(z)):
		if z[j] != strt + j * k:
			moves += 1
	minz.append(moves)
	minz_num.append(strt)
ansf = min(minz)
a = minz_num[minz.index(ansf)]
ans = ''
for i in range(0, len(z)):
	if z[i] > a + i * k:
		ans += '-' + ' ' + str(i + 1) + ' ' + str(abs(z[i] - a - i * k)) + '\n'
	if z[i] < a + i * k:
		ans += '+' + ' ' + str(i + 1) + ' ' + str(abs(z[i] - a - i * k)) + '\n'
print(ansf)
print(ans)


(n, k) = map(int, input().split())
tree = list(map(int, input().split()))
min_action = 1010
for i in range(1, 1001):
	count = 0
	for j in range(0, n):
		if tree[j] != i + j * k:
			count += 1
	if min_action > count:
		min_action = count
		ans = i
print(min_action)
for i in range(0, n):
	if ans + i * k < tree[i]:
		print('- %s %s' % (i + 1, tree[i] - ans - i * k))
	elif ans + i * k > tree[i]:
		print('+ %s %s' % (i + 1, ans + i * k - tree[i]))


from collections import Counter
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
t = [arr[i] - k * i for i in range(n)]
d = Counter(t)
cnt = 0
for (key, val) in d.items():
	if key <= 0:
		continue
	if val > cnt:
		cnt = val
		best = key
print(n - cnt)
for i in range(n):
	x = arr[i] - k * i - best
	if x < 0:
		print('{} {} {}'.format('+', i + 1, -x))
	if x > 0:
		print('{} {} {}'.format('-', i + 1, x))


from sys import stdin
__author__ = 'artyom'

def read_int_ary():
	return map(int, stdin.readline().strip().split())
(n, k) = read_int_ary()
a = list(read_int_ary())
mx = i_mx = 0
for i in range(n):
	if a[i] - k * i <= 0:
		continue
	sh = a[i] + k
	count = 0
	for j in range(i + 1, n):
		if a[j] == sh:
			count += 1
		sh += k
	if count > mx:
		mx = count
		i_mx = i
print(n - mx - 1)
sh = a[i_mx] - k * i_mx
for i in range(n):
	if a[i] < sh:
		print('+ ' + str(i + 1) + ' ' + str(sh - a[i]))
	elif a[i] > sh:
		print('- ' + str(i + 1) + ' ' + str(a[i] - sh))
	sh += k


from collections import Counter
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = [a[i] - k * i for i in range(n)]
occ = Counter(t)
ans = 0
for (key, value) in occ.items():
	if key <= 0:
		continue
	if value > ans:
		ans = value
		best = key
print(n - ans)
for i in range(n):
	x = a[i] - i * k - best
	if x > 0:
		print('{} {} {}'.format('-', i + 1, x))
	elif x < 0:
		print('{} {} {}'.format('+', i + 1, -x))


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
for i in range(n):
	cur = 0
	for j in range(n):
		if j > i:
			if a[j] == a[i] + (j - i) * k:
				cur += 1
		elif j < i:
			if a[j] == a[i] - (i - j) * k:
				cur += 1
	b.append(cur)
(t, cur) = (-1, -1)
for i in range(len(b)):
	if b[i] > cur and a[i] > k * i:
		cur = b[i]
		t = i
res = []
for i in range(n):
	c = -a[i] + ((i - t) * k + a[t])
	if c != 0:
		res.append([i + 1, c])
print(len(res))
for (i, j) in res:
	if j < 0:
		print('-', str(i), -j)
	else:
		print('+', str(i), j)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
max_p = n
max_i = -1
for i in range(n):
	p = 0
	if a[i] - k * i >= 1:
		for j in range(n):
			if j < i:
				if a[j] != a[i] - k * (i - j):
					p += 1
			elif a[j] != a[i] + k * (j - i):
				p += 1
		if p < max_p:
			max_p = p
			max_i = i
print(max_p)
for i in range(n):
	if i < max_i:
		if a[i] < a[max_i] - k * (max_i - i):
			print('+', i + 1, a[max_i] - k * (max_i - i) - a[i])
		elif a[i] > a[max_i] - k * (max_i - i):
			print('-', i + 1, a[i] - (a[max_i] - k * (max_i - i)))
	elif i > max_i:
		if a[i] < a[max_i] + k * (i - max_i):
			print('+', i + 1, a[max_i] + k * (i - max_i) - a[i])
		elif a[i] > a[max_i] + k * (i - max_i):
			print('-', i + 1, a[i] - (a[max_i] + k * (i - max_i)))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
best = n
best_ind = -1
for i in range(1, 1001):
	X = [i + k * j for j in range(n)]
	cnt = 0
	for j in range(n):
		if X[j] != A[j]:
			cnt += 1
	if cnt < best:
		best_ind = i
	best = min(best, cnt)
ans = [best_ind + i * k for i in range(n)]
print(best)
for i in range(n):
	if ans[i] < A[i]:
		print('- ' + str(i + 1) + ' ' + str(-(-A[i] + ans[i])))
	elif ans[i] > A[i]:
		print('+ ' + str(i + 1) + ' ' + str(-(A[i] - ans[i])))
	else:
		continue