Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples:  $p_1(4) = [1, 2, 3, 4]$;  $p_2(4) = [2, 1, 3, 4]$;  $p_3(4) = [3, 1, 2, 4]$;  $p_4(4) = [4, 1, 2, 3]$. 

You are given an array $x_1, x_2, \dots, x_m$ ($1 \le x_i \le n$).

Let $pos(p, val)$ be the position of the element $val$ in $p$. So, $pos(p_1(4), 3) = 3, pos(p_2(4), 2) = 1, pos(p_4(4), 4) = 1$.

Let's define a function $f(p) = \sum\limits_{i=1}^{m - 1} |pos(p, x_i) - pos(p, x_{i + 1})|$, where $|val|$ is the absolute value of $val$. This function means the sum of distances between adjacent elements of $x$ in $p$.

Your task is to calculate $f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$.


-----Input-----

The first line of the input contains two integers $n$ and $m$ ($2 \le n, m \le 2 \cdot 10^5$) — the number of elements in each permutation and the number of elements in $x$.

The second line of the input contains $m$ integers ($m$, not $n$) $x_1, x_2, \dots, x_m$ ($1 \le x_i \le n$), where $x_i$ is the $i$-th element of $x$. Elements of $x$ can repeat and appear in arbitrary order.


-----Output-----

Print $n$ integers: $f(p_1(n)), f(p_2(n)), \dots, f(p_n(n))$.


-----Examples-----
Input
4 4
1 2 3 4

Output
3 4 6 5 

Input
5 5
2 1 5 3 5

Output
9 8 12 6 8 

Input
2 10
1 2 1 1 2 2 2 2 2 2

Output
3 3 



-----Note-----

Consider the first example:

$x = [1, 2, 3, 4]$, so  for the permutation $p_1(4) = [1, 2, 3, 4]$ the answer is $|1 - 2| + |2 - 3| + |3 - 4| = 3$;  for the permutation $p_2(4) = [2, 1, 3, 4]$ the answer is $|2 - 1| + |1 - 3| + |3 - 4| = 4$;  for the permutation $p_3(4) = [3, 1, 2, 4]$ the answer is $|2 - 3| + |3 - 1| + |1 - 4| = 6$;  for the permutation $p_4(4) = [4, 1, 2, 3]$ the answer is $|2 - 3| + |3 - 4| + |4 - 1| = 5$. 

Consider the second example:

$x = [2, 1, 5, 3, 5]$, so  for the permutation $p_1(5) = [1, 2, 3, 4, 5]$ the answer is $|2 - 1| + |1 - 5| + |5 - 3| + |3 - 5| = 9$;  for the permutation $p_2(5) = [2, 1, 3, 4, 5]$ the answer is $|1 - 2| + |2 - 5| + |5 - 3| + |3 - 5| = 8$;  for the permutation $p_3(5) = [3, 1, 2, 4, 5]$ the answer is $|3 - 2| + |2 - 5| + |5 - 1| + |1 - 5| = 12$;  for the permutation $p_4(5) = [4, 1, 2, 3, 5]$ the answer is $|3 - 2| + |2 - 5| + |5 - 4| + |4 - 5| = 6$;  for the permutation $p_5(5) = [5, 1, 2, 3, 4]$ the answer is $|3 - 2| + |2 - 1| + |1 - 4| + |4 - 1| = 8$.

Difficulty: introductory

Starter code:

Solutions:
n, m = map(int, input().split())
x = list(map(int, input().split()))

foo = [0 for _ in range(2+n)]

for i in range(1, m) :
    p, q = x[i-1], x[i]

    if p == q : continue

    r = min(p, q)

    s = max(p, q)

    foo[0] += abs(p-q)
    foo[r] -= abs(p-q)
    foo[r] += max(p, q) - 1
    foo[r+1] -= max(p, q) - 1

    foo[r+1] += abs(p-q)-1
    foo[s] -= abs(p-q)-1

    foo[s] += min(p, q)
    foo[s+1] -= min(p, q)

    foo[s+1] += abs(p-q)
    foo[n+1] -= abs(p-q)

    # print(p, q, foo)

for i in range(1,n+1) :
    foo[i] += foo[i-1]
    print(foo[i], end=' ')
print()


import io, sys, atexit, os
import math as ma
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


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


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


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)






mm = 1000000007

def solve ():
	t = 1
	for tt in range (t):
		n,m=num()
		a=li()
		p=[0]*(n+1)
		for i in range(0,m-1):
			if(a[i]==a[i+1]):
				continue
			l=a[i]
			r=a[i+1]
			if(l>r):
				l,r=r,l
			hp=r-l
			kp=l-1
			ko=r-1
			p[ko+1]+=hp
			p[n]-=hp
			p[kp]-=hp
			p[0]+=hp
			p[kp+1]+=hp-1
			p[ko]-=(hp-1)
			p[ko]+=(l)
			p[ko+1]-=(l)
			p[kp]+=(r-1)
			p[kp+1]-=(r-1)
		for i in range(1,n+1):
			p[i]=p[i]+p[i-1]
		print(*(p[0:n]))
















def __starting_point():
	solve ()
__starting_point()

n, m = map(int, input().split())
a = list(map(int, input().split()))

left = [0] * (n + 1)
left_sum = left[:]
right = left[:]
cross = left[:]
rang = left[:]
ans = left[:n]
total = 0

for i in range(1, m):
    p = a[i - 1]
    q = a[i]
    if p == q:
        continue
    if q < p:
        p, q = q, p
    total += q - p
    rang[p] += 1
    rang[q - 1] -= 1
    right[p] += 1
    left[q] += 1
    left_sum[q] += q - p

start = 0
for i in range(n):
    cross[i] = start
    start += rang[i]

ans[0] = total
for i in range(2, n + 1):
    ans[i - 1] = total - cross[i] + left[i] * i - 2 * left_sum[i] + (i - 1) * right[i]
print(*ans)

N, M = map(int, input().split())
*X, = map(int, input().split())
for i in range(M):
    X[i] -= 1

R = 0
S = [0]*N
T = [0]*N
D = [0]*(N+1)
for i in range(M-1):
    if X[i] < X[i+1]:
        D[X[i]+1] += 1
        D[X[i+1]] -= 1
    elif X[i] > X[i+1]:
        D[X[i+1]+1] += 1
        D[X[i]] -= 1

    d = abs(X[i] - X[i+1])
    S[X[i]] += d
    S[X[i+1]] += d
    if X[i] < X[i+1]:
        T[X[i]] += X[i+1]
        T[X[i+1]] += X[i] + 1
    elif X[i] > X[i+1]:
        T[X[i]] += X[i+1] + 1
        T[X[i+1]] += X[i]
    R += d
for i in range(N-1):
    D[i+1] += D[i]
ans = [0]*N
for i in range(N):
    ans[i] = R + T[i] - S[i] - D[i]
print(*ans)

import sys
 
n,m = [int(x) for x in input().split()]
X = [int(x) - 1 for x in input().split()]
 
s = 0
right = [[] for _ in range(n)]
left = [[] for _ in range(n)]
for j in range(m - 1):
    a,b = X[j], X[j + 1]
    if a == b:
        continue
    if a > b:
       a,b = b,a 
    right[a].append(b)
    left[b].append(a)
    s += b - a
 
out = [s]
for i in range(1, n): 
    for b in right[i - 1]:
        s -= b
    for b in left[i - 1]:
        s -= b + 1
 
    for b in right[i]:
        s -= b - i
    for b in left[i]:
        s -= i - b - 1
    
    for b in right[i]:
        s += b
    for b in left[i]:
        s += b + 1
 
    for b in right[i - 1]:
        s += b - (i - 1) - 1
    for b in left[i - 1]:
        s += (i - 1) - b
    out.append(s)
print (' '.join(str(x) for x in out))

# print(sum(map(lambda x: len(str(x).strip("47")) == 0, range(int(input()) + 1))))

n, m = map(int, input().split())
adj = [0 for _ in range(n + 1)]
cnt = [0 for _ in range(n + 1)]
x = map(int, input().split())
f1 = 0
x1 = next(x)
for i in range(m - 1):
    x2 = next(x)
    minx = min(x1, x2)
    maxx = x1 + x2 - minx
    x1 = x2
    dx = maxx - minx
    if dx > 0:
        adj[minx] += minx - 1
        adj[maxx] += minx - dx
        f1 += dx
        if dx >= 2:
            cnt[minx + 1] += 1
            cnt[maxx] -= 1
print(f1, end=' ')
c = cnt[1]
for i in range(2, n + 1):
    c += cnt[i]
    print(f1 - c + adj[i], end=' ')


# print(sum(map(lambda x: len(str(x).strip("47")) == 0, range(int(input()) + 1))))

n, m = map(int, input().split())
adj = [0 for _ in range(n + 1)]
cnt = [0 for _ in range(n + 1)]
x = map(int, input().split())
f1 = 0
x1 = next(x)
for i in range(m - 1):
    x2 = next(x)
    minx = min(x1, x2)
    maxx = x1 + x2 - minx
    x1 = x2
    dx = maxx - minx
    if dx > 0:
        adj[minx] += minx - 1
        adj[maxx] += minx - dx
        f1 += dx
        if dx >= 2:
            cnt[minx + 1] += 1
            cnt[maxx] -= 1
print(f1, end=' ')
c = cnt[1]
for i in range(2, n + 1):
    c += cnt[i]
    print(f1 - c + adj[i], end=' ')


n, m = map(int, input().split())
adj = [0 for _ in range(n + 1)]
cnt = [0 for _ in range(n + 1)]
x = map(int, input().split())
f1 = 0
x1 = next(x)
for i in range(m - 1):
    x2 = next(x)
    minx = min(x1, x2)
    maxx = x1 + x2 - minx
    x1 = x2
    dx = maxx - minx
    if dx > 0:
        adj[minx] += minx - 1
        adj[maxx] += minx - dx
        f1 += dx
        if dx >= 2:
            cnt[minx + 1] += 1
            cnt[maxx] -= 1
print(f1, end=' ')
c = cnt[1]
for i in range(2, n + 1):
    c += cnt[i]
    print(f1 - c + adj[i], end=' ')


import sys
input = sys.stdin.readline

n,m=map(int,input().split())
X=list(map(int,input().split()))

PLUS=[[0,0] for i in range(n+1)]

DIFF1=[0]*(n+1)
DIFF2=[0]*(n+1)


for i in range(m):
    if 0<=i-1:
        if X[i-1]<X[i]-1:
            DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(X[i-1]+1-X[i])

        elif X[i-1]==X[i]-1:
            DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(1-X[i])

        elif X[i-1]>=X[i]+1:
            DIFF1[X[i]]+=abs(X[i-1]-1)-abs(X[i-1]-X[i])

    if i+1<m:
        if X[i+1]<X[i]-1:
            DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(X[i+1]+1-X[i])

        elif X[i+1]==X[i]-1:
            DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(1-X[i])

        elif X[i+1]>=X[i]+1:
            DIFF1[X[i]]+=abs(X[i+1]-1)-abs(X[i+1]-X[i])

#print(DIFF1)

for i in range(m):
    if 0<=i-1:
        if X[i-1]<X[i]:
            DIFF2[X[i]]+=abs(X[i-1]-X[i])-abs(X[i-1]+1-1)

        elif X[i-1]>X[i]+1:
            DIFF2[X[i]]+=abs(X[i-1]-X[i]-1)-abs(X[i-1]-1)

    if i+1<m:
        if X[i+1]<X[i]:
            DIFF2[X[i]]+=abs(X[i+1]-X[i])-abs(X[i+1]+1-1)

        elif X[i+1]>X[i]+1:
            DIFF2[X[i]]+=abs(X[i+1]-X[i]-1)-abs(X[i+1]-1)

#print(DIFF2)



ANS=0
for i in range(1,m):
    ANS+=abs(X[i]-X[i-1])

print(ANS,end=" ")

for i in range(2,n+1):
    ANS+=DIFF1[i]+DIFF2[i-1]
    print(ANS,end=" ")


def pos(x, i):
    if x > i:
        return x
    elif x < i:
        return x + 1
    else:
        return 1


n, m = map(int, input().split())
x = list(map(int, input().split()))
delta_ = [0] * (n + 2)
func = sum(abs(x[i + 1] - x[i]) for i in range(m - 1))
for i in range(m):
    if x[i] < n:
        if i > 0:
            prev_l = abs(pos(x[i], x[i]) - pos(x[i - 1], x[i]))
            cur_l = abs(pos(x[i], x[i] + 1) - pos(x[i - 1], x[i] + 1))
            delta_[x[i] + 1] += cur_l - prev_l
        if i < m - 1:
            prev_r = abs(pos(x[i], x[i]) - pos(x[i + 1], x[i]))
            cur_r = abs(pos(x[i], x[i] + 1) - pos(x[i + 1], x[i] + 1))
            delta_[x[i] + 1] += cur_r - prev_r
    if x[i] > 1:
        if i > 0:
            prev_l = abs(pos(x[i], x[i] - 1) - pos(x[i - 1], x[i] - 1))
            cur_l = abs(pos(x[i], x[i]) - pos(x[i - 1], x[i]))
            delta_[x[i]] += cur_l - prev_l
        if i < m - 1:
            prev_r = abs(pos(x[i], x[i] - 1) - pos(x[i + 1], x[i] - 1))
            cur_r = abs(pos(x[i], x[i]) - pos(x[i + 1], x[i]))
            delta_[x[i]] += cur_r - prev_r

for i in range(1, n + 1):
    print(func, end=" ")
    func += delta_[i + 1]



f=[]

def mdy(l,r,x):
	f[l]+=x
	f[r+1]-=x

n,m=map(int,input().split())

P=list(range(n+2))

for i in range(n+5):
	f.append(0)

a=list(map(int,input().split()))

for i in range(m-1):
	l=a[i]
	r=a[i+1]
	if l==r:
		continue
	if l>r:
		(l,r)=(r,l)
	mdy(1,l-1,r-l)
	mdy(l,l,r-1)
	mdy(l+1,r-1,r-l-1)
	mdy(r,r,l)
	mdy(r+1,n,r-l)

for i in P[1:n+1]:
	f[i]+=f[i-1]
	print(f[i],end=" ")

def readint():
    return [int(e) for e in input().split()]

n, m = readint()
x = readint()

sm = [0] * (n+2)

def addvalue(s, e, v):
    if s > e:
        return
    sm[s] += v
    sm[e+1] -= v

for (a, b) in zip(x, x[1:]):
    if a == b:
        continue
    if a > b:
        a, b = b, a
    addvalue(1, a-1, b - a)
    addvalue(a, a, b-1)
    addvalue(a+1, b-1, b - a - 1)
    addvalue(b, b, a)
    addvalue(b+1, n, b - a)

for i in range(1, n+2):
    sm[i] += sm[i-1]

print(' '.join(map(str, sm[1:n+1])))
    
    


f=[]
 
def mdy(l,r,x):
	f[l]+=x
	f[r+1]-=x
 
n,m=map(int,input().split())
 
P=list(range(n+4))
 
for j in range(n+7):
	f.append(0)
 
a=list(map(int,input().split()))
 
for j in range(m-1):
	l=a[j]
	r=a[j+1]
	if l==r:
		continue
	if l>r:
		(l,r)=(r,l)
	mdy(1,l-1,r-l)
	mdy(l,l,r-1)
	mdy(l+1,r-1,r-l-1)
	mdy(r,r,l)
	mdy(r+1,n,r-l)
 
for j in P[1:n+1]:
	f[j]+=f[j-1]
	print(f[j],end=" ")

3

import array
import math
import os
import sys


def main():
    N, M = read_ints()
    X = [x - 1 for x in read_ints()]
    print(*solve(N, M, X))


def solve(N, M, X):
    pos = list(range(N))
    pairs = [dict() for _ in range(N)]
    fsum = 0
    for i in range(M - 1):
        a = X[i]
        b = X[i + 1]
        if a == b:
            continue
        if b not in pairs[a]:
            pairs[a][b] = 0
        if a not in pairs[b]:
            pairs[b][a] = 0
        pairs[a][b] += 1
        pairs[b][a] += 1
        fsum += abs(pos[a] - pos[b])

    ans = [fsum]
    fst = 0
    for i in range(N - 1):
        j = i + 1
        pi = pos[i]
        pj = pos[j]

        d = 0
        for k, c in pairs[i].items():
            if k == j:
                continue
            pk = pos[k]
            d -= abs(pi - pk) * c
            d += abs(pj - pk) * c
        for k, c in pairs[j].items():
            if k == i:
                continue
            pk = pos[k]
            d -= abs(pj - pk) * c
            d += abs(pi - pk) * c

        fsum += d
        ans.append(fsum)
        pos[i], pos[j] = pj, pi

    return ans


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline
     
n,m=map(int,input().split())
X=list(map(int,input().split()))
     
PLUS=[[0,0] for i in range(n+1)]
     
DIFF1=[0]*(n+1)
DIFF2=[0]*(n+1)
     
     
for i in range(m):
    if 0<=i-1:
        if X[i-1]<X[i]-1:
            DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(X[i-1]+1-X[i])
     
        elif X[i-1]==X[i]-1:
            DIFF1[X[i]]+=abs(X[i-1]+1-1)-abs(1-X[i])
     
        elif X[i-1]>=X[i]+1:
            DIFF1[X[i]]+=abs(X[i-1]-1)-abs(X[i-1]-X[i])
     
    if i+1<m:
        if X[i+1]<X[i]-1:
            DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(X[i+1]+1-X[i])
     
        elif X[i+1]==X[i]-1:
            DIFF1[X[i]]+=abs(X[i+1]+1-1)-abs(1-X[i])
     
        elif X[i+1]>=X[i]+1:
            DIFF1[X[i]]+=abs(X[i+1]-1)-abs(X[i+1]-X[i])
     
#print(DIFF1)
     
for i in range(m):
    if 0<=i-1:
        if X[i-1]<X[i]:
            DIFF2[X[i]]+=abs(X[i-1]-X[i])-abs(X[i-1]+1-1)
     
        elif X[i-1]>X[i]+1:
            DIFF2[X[i]]+=abs(X[i-1]-X[i]-1)-abs(X[i-1]-1)
     
    if i+1<m:
        if X[i+1]<X[i]:
            DIFF2[X[i]]+=abs(X[i+1]-X[i])-abs(X[i+1]+1-1)
     
        elif X[i+1]>X[i]+1:
            DIFF2[X[i]]+=abs(X[i+1]-X[i]-1)-abs(X[i+1]-1)
     
#print(DIFF2)
     
     
     
ANS=0
for i in range(1,m):
    ANS+=abs(X[i]-X[i-1])
     
print(ANS,end=" ")
     
for i in range(2,n+1):
    ANS+=DIFF1[i]+DIFF2[i-1]
    print(ANS,end=" ")



def __starting_point():
    n, m = input().split(' ')
    n = int(n)
    m = int(m)
    x = [int(i) for i in input().split(' ')]
    pre = [0] * (n + 2)
    tmp = 0
    for i in range(m - 1):
        a, b = x[i], x[i + 1]
        if a > b:
            a, b = b, a
        if a == b:
            continue
        pre[1] += b - a
        pre[a] -= b - a
        pre[a] += b - 1
        pre[a + 1] -= b - 1
        pre[a + 1] += b - a - 1
        pre[b] -= b - a - 1
        pre[b] += a
        pre[b + 1] -= a
        pre[b + 1] += b - a
        pre[n + 1] -= b - a
    for i in range(1,n+1):
        pre[i] += pre[i-1]
        print(pre[i],end=' ')
    print('')
__starting_point()

f=[]
 
def mdy(l,r,x):
	f[l]+=x
	f[r+1]-=x
 
n,m=map(int,input().split())
 
P=list(range(n+2))
 
for i in range(n+5):
	f.append(0)
 
a=list(map(int,input().split()))
 
for i in range(m-1):
	l=a[i]
	r=a[i+1]
	if l==r:
		continue
	if l>r:
		(l,r)=(r,l)
	mdy(1,l-1,r-l)
	mdy(l,l,r-1)
	mdy(l+1,r-1,r-l-1)
	mdy(r,r,l)
	mdy(r+1,n,r-l)
 
for i in P[1:n+1]:
	f[i]+=f[i-1]
	print(f[i],end=" ")

n,m=map(int,input().split())
x=[int(x1) for x1 in input().split()]

pre1=[0]*(n+2)
pre2=[0]*(n+1)
pre3=[0]*(n+1)

for i in range(0,len(x)-1):
    a=min(x[i],x[i+1])
    b=max(x[i],x[i+1])

    if(b-a>1):

        pre1[a+1]+=1
        pre1[b]+=-1

    if(a!=b):
        pre2[a]+=(b-1)-(b-a)#(b-a-1)+b
        pre3[b]+=a-(b-a)




t=0
for i in range(0,len(pre1)):
    pre1[i]=t+pre1[i]
    t=pre1[i]

#print('pre1',pre1)
#print('pre2',pre2)
#print('pre3',pre3)


ans=0
for i in range(0,m-1):
    ans+=abs(x[i]-x[i+1])



print(ans,end=" ")
for i in range(2,n+1):
    temp=ans+pre2[i]+pre3[i]+-pre1[i]
    print(temp,end=" ")

print(" ")
    


n,m=map(int,input().split())
x=[int(x1) for x1 in input().split()]

pre1=[0]*(n+2)
pre2=[0]*(n+1)
pre3=[0]*(n+1)

for i in range(0,len(x)-1):
    a=min(x[i],x[i+1])
    b=max(x[i],x[i+1])

    if(b-a>1):

        pre1[a+1]+=1
        pre1[b]+=-1

    if(a!=b):
        pre2[a]+=(b-1)-(b-a)
        pre3[b]+=a-(b-a)


t=0
for i in range(0,len(pre1)):
    pre1[i]=t+pre1[i]
    t=pre1[i]


ans=0
for i in range(0,m-1):
    ans+=abs(x[i]-x[i+1])



print(ans,end=" ")
for i in range(2,n+1):
    temp=ans+pre2[i]+pre3[i]+-pre1[i]
    print(temp,end=" ")

print(" ")
    


import math
import functools
from collections import defaultdict

n, m = map(int, input().split(' '))

v = [i for i in map(int, input().split(' '))]

s = [0 for i in range(n + 2)]

for i in range(m - 1):
    if abs(v[i] - v[i + 1]) < 2:
        continue
    s[min(v[i], v[i + 1]) + 1] += 1
    s[max(v[i], v[i + 1])] -= 1

p = 0

for i in range(m - 1):
    p += abs(v[i] - v[i + 1])

ans = [0 for i in range(n + 2)]

d = 0

for i in range(n + 2):
    d += s[i]
    ans[i] = d

a = defaultdict(lambda : 0, {})
b = defaultdict(lambda : [], {})

for i in range(m - 1):
    if v[i] == v[i + 1]:
        continue
    a[min(v[i], v[i + 1])] += 1
    b[max(v[i], v[i + 1])].append(min(v[i], v[i + 1]))

for i in range(1, n + 1):
    q = p
    q = ans[i]
    q = a[i] * (i - 1)
    q = len(b[i]) * i
    q = 2 * sum(b[i])
    print(p -
          ans[i] +
          a[i] * (i - 1) -
          len(b[i]) * i +
          2 * sum(b[i]), end=' ')

import math
import functools
from collections import defaultdict

n, m = map(int, input().split(' '))

v = [i for i in map(int, input().split(' '))]

s = [0 for i in range(n + 2)]

for i in range(m - 1):
    if abs(v[i] - v[i + 1]) < 2:
        continue
    s[min(v[i], v[i + 1]) + 1] += 1
    s[max(v[i], v[i + 1])] -= 1

p = 0

for i in range(m - 1):
    p += abs(v[i] - v[i + 1])

ans = [0 for i in range(n + 2)]

d = 0

for i in range(n + 2):
    d += s[i]
    ans[i] = d

a = defaultdict(lambda : 0, {})
b = defaultdict(lambda : [], {})

for i in range(m - 1):
    if v[i] == v[i + 1]:
        continue
    a[min(v[i], v[i + 1])] += 1
    b[max(v[i], v[i + 1])].append(min(v[i], v[i + 1]))

for i in range(1, n + 1):
    q = p
    q = ans[i]
    q = a[i] * (i - 1)
    q = len(b[i]) * i
    q = 2 * sum(b[i])
    print(p -
          ans[i] +
          a[i] * (i - 1) -
          len(b[i]) * i +
          2 * sum(b[i]), end=' ')

#bouncipie
def readint():
    return [int(e) for e in input().split()]
 
n, m = readint()
x = readint()
 
sm = [0] * (n+2)
 
def addvalue(s, e, v):
    if s > e:
        return
    sm[s] += v
    sm[e+1] -= v
 
for (a, b) in zip(x, x[1:]):
    if a == b:
        continue
    if a > b:
        a, b = b, a
    addvalue(1, a-1, b - a)
    addvalue(a, a, b-1)
    addvalue(a+1, b-1, b - a - 1)
    addvalue(b, b, a)
    addvalue(b+1, n, b - a)
 
for i in range(1, n+2):
    sm[i] += sm[i-1]
 
print(' '.join(map(str, sm[1:n+1])))