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: interview

Starter code:

Solutions:
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))

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



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 = list(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:
    return
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(" ")))
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 = 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)))


n, k = list(map(int, input().split()))
trees = list(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))



def check_bounds(start):
    return heights[start]-start*k >= 1

n,k = list(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 = 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)))


n,k=list(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


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






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
    #print(r)
    for i in r:
        if (h[i+1] - h[i] != k):
            h[i] = h[i+1] - k
            counter += 1
    #print(list(range(x+1,n)))
    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
    #print(h)
    r = list(range(x))
    r.reverse()
    #print(r)
    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
    #print(list(range(x+1,n)))
    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)


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=list(map(int,input().split()))

z=[int(x) for x in input().split()]
lim=max(z)
ctr=10000000

minz=[]
minz_num=[]#no. of moves for every element in z
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))

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

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


n, k = list(map(int, input().split()))
trees = list(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))


# 402B

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

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)


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

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