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

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Complete search


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


string = str(input())
astring = str(input()) + ' '
word = ''
alist = []
n = int(string[:string.index(' ')])
k = int(string[string.index(' ') + 1:])
for char in astring:
	if char != ' ':
		word += char
	else:
		alist.append(int(word))
		word = ''
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)


(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())
trees = map(int, input().split())
deltas = [tree - i * k - 1 for (i, tree) in enumerate(trees)]
freqs = [0] * 1000
for delta in deltas:
	if delta >= 0:
		freqs[delta] += 1
d = freqs.index(max(freqs))
print(sum((delta != d for delta in deltas)))
for (i, delta) in enumerate(deltas):
	if delta > d:
		print('- %d %d' % (i + 1, delta - d))
	elif delta < d:
		print('+ %d %d' % (i + 1, d - delta))


(n, k) = list(map(int, input().split(' ')))
ts = list(map(int, input().split(' ')))
aps = dict()
for i in range(n):
	f = ts[i] - k * i
	if f > 0:
		aps[f] = aps.get(f, 0) + 1
af = max([i for i in list(aps.keys())], key=lambda x: aps[x])
print(len([1 for i in range(n) if ts[i] != af + k * i]))

def action(af, i, ts, k):
	if ts[i] > af + k * i:
		return '- %i %i' % (i + 1, ts[i] - (af + k * i))
	elif ts[i] < af + k * i:
		return '+ ' + str(i + 1) + ' ' + str(af + k * i - ts[i])
	else:
		return None
acts = [action(af, i, ts, k) for i in range(n)]
acts = [act for act in acts if act]
print('\n'.join(acts))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = 1000
first = 1
for i in range(n):
	if a[i] > k * i:
		now = 0
		f = a[i] - k * i
		for j in range(i):
			if a[j] != f + k * j:
				now += 1
		for j in range(i + 1, n):
			if a[j] != f + j * k:
				now += 1
		if now < p:
			p = now
			first = f
print(p)
for i in range(n):
	if a[i] != first + k * i:
		print('+' if a[i] < first + k * i else '-', i + 1, abs(a[i] - first - k * i))


def dist(A, B):
	res = 0
	for i in range(len(A)):
		if A[i] != B[i]:
			res += 1
	return res

def generate_new(number):
	nonlocal n, k
	R = [0] * n
	for i in range(n):
		R[i] = number
		number += k
	return R
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
N = 1009
res = [0] * n
res_dist = N
for i in range(1, N):
	B = generate_new(i)
	cur_dist = dist(A, B)
	if cur_dist < res_dist:
		res = B
		res_dist = cur_dist
print(res_dist)
for i in range(len(A)):
	if A[i] < res[i]:
		print('+', i + 1, res[i] - A[i])
	elif A[i] > res[i]:
		print('-', i + 1, A[i] - res[i])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
n = len(a)
ans = 0
s = 0
for i in range(1, 1001):
	cc = 0
	for j in range(0, n):
		cc += int(a[j] == i + j * k)
	if cc > ans:
		ans = cc
		s = i
print(n - ans)
to = s
for j in range(0, n):
	if a[j] > to:
		print('-', j + 1, a[j] - to)
	if a[j] < to:
		print('+', j + 1, -a[j] + to)
	to += k


(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()))
MAX = 1000
cost = n - 1
start = a[0]
for h in range(1, MAX, 1):
	c = 0
	for (i, height) in enumerate(a):
		c += int(h + i * k != height)
	if c < cost:
		cost = c
		start = h
print(cost)
for (i, height) in enumerate(a):
	desired_height = start + i * k
	if desired_height != height:
		diff = height - desired_height
		if diff > 0:
			print('{0} {1} {2}'.format('-', i + 1, abs(diff)))
		else:
			print('{0} {1} {2}'.format('+', i + 1, abs(diff)))


from sys import stdin, stdout
from os import path
rd = lambda : stdin.readline().strip()
wr = stdout.write
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
import time, math
(x, y) = map(int, rd().split())
mylist = list(map(int, rd().split()))
mn = 100000
first = 0
k = 1
while k <= 1000:
	counter = None
	if mylist[0] == k:
		counter = 0
	else:
		counter = 1
	arr = [k]
	for i in range(1, len(mylist)):
		if k + i * y != mylist[i]:
			counter += 1
	if counter < mn:
		mn = counter
		first = k
	if mn == 0:
		break
	k += 1
arr = [first]
for _ in range(len(mylist) - 1):
	arr.append(arr[-1] + y)
if mn == 0:
	print(0)
else:
	print(mn)
	for i in range(len(mylist)):
		res = arr[i] - mylist[i]
		if res != 0:
			if res < 0:
				print('-', i + 1, abs(res))
			else:
				print('+', i + 1, abs(res))


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


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
l2 = [l[i] - k * i for i in range(n) if l[i] > k * i]
sl = set(l2)
(base, a) = (1, 0)
for x in sl:
	cnt = l2.count(x)
	if cnt > a:
		base = x
		a = cnt
print(n - a)
for i in range(n):
	if l[i] < i * k + base:
		print('+', i + 1, i * k + base - l[i])
	elif l[i] > i * k + base:
		print('-', i + 1, l[i] - (i * k + base))


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) = list(map(int, input().split()))
a = [int(x) for x in input().split()]
a2 = [a[i] - k * i for i in range(n)]
bs = set(a2)
(bestKey, maxCount) = (1, 0)
for key in bs:
	if key <= 0:
		continue
	count = a2.count(key)
	if count > maxCount:
		bestKey = key
		maxCount = count
b = bestKey
print(n - maxCount)
for i in range(n):
	if a[i] > i * k + b:
		print('-', i + 1, a[i] - (i * k + b))
	elif a[i] < i * k + b:
		print('+', i + 1, i * k + b - a[i])


(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())
t = list(map(int, input().split()))
p = [0] * 1001
x = y = d = 0
for h in t:
	s = h - d
	if s > 0:
		p[s] += 1
		if p[s] > x:
			(x, y) = (p[s], s)
	d += k
d = 0
for (i, h) in enumerate(t):
	t[i] = y - h + d
	d += k
t = ['- ' + str(i) + ' ' + str(-s) if s < 0 else '+ ' + str(i) + ' ' + str(s) for (i, s) in enumerate(t, 1) if s]
print(n - x)
print('\n'.join(t))


(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]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(mx, idx) = (0, 0)
for i in range(1, 1001):
	t = 0
	for j in range(n):
		t += arr[j] == i + j * k
	if t > mx:
		mx = t
		idx = i
res = str(n - mx) + '\n'
for j in range(n):
	if arr[j] > idx:
		res += '- ' + str(j + 1) + ' ' + str(arr[j] - idx) + '\n'
	if arr[j] < idx:
		res += '+ ' + str(j + 1) + ' ' + str(-arr[j] + idx) + '\n'
	idx += k
print(res[:-1])


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 itertools import groupby
R = lambda : map(int, input().split())
(n, k) = R()
a = list(R())
b = sorted((a[i] - k * i for i in range(1, n)))
c = [(len(list(g[1])), g[0]) for g in groupby(b) if g[0] > 0]
if len(c) > 0:
	m = max((x for (x, y) in c))
	c = [x for x in c if x[0] == m]
else:
	c = [(0, a[0])]
d = 0
for i in range(len(c)):
	if c[i][1] == a[0]:
		d = i
		print(n - c[d][0] - 1)
		break
else:
	print(n - c[d][0])
for i in range(n):
	ai = c[d][1] + k * i
	if ai > a[i]:
		print('+ {} {}'.format(i + 1, ai - a[i]))
	elif ai < a[i]:
		print('- {} {}'.format(i + 1, a[i] - ai))


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


def main():
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	d = {}
	(best, best_first) = (0, -1)
	for (i, v) in enumerate(a):
		good_first = v - k * i
		if good_first >= 1:
			if good_first not in d:
				d[good_first] = 0
			d[good_first] += 1
			if d[good_first] > best:
				best = d[good_first]
				best_first = good_first
	print(n - best)
	for (i, v) in enumerate(a):
		diff = best_first - (v - k * i)
		if diff > 0:
			print('+', i + 1, diff)
		elif diff < 0:
			print('-', i + 1, -diff)
main()


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
m = 10000000000
s = 0
p = 0
for i in range(1, 1001):
	x = 0
	for j in range(0, a):
		h = i + j * b
		if l[j] == h:
			x = x + 1
	if x >= s:
		p = i
		s = x
print(a - s)
for i in range(0, a):
	s = ''
	if p + i * b - l[i] == 0:
		continue
	elif p + i * b - l[i] > 0:
		s = '+ ' + str(i + 1) + ' ' + str(abs(p + i * b - l[i]))
	else:
		s = '- ' + str(i + 1) + ' ' + str(abs(p + i * b - l[i]))
	print(s)