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

Source: codeforces | Difficulty: HARD
Tags: Mathematics


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


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


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 io, sys, atexit, os
import math as ma
from sys import exit
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])
solve()


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


from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, pprint, fractions
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def err(x):
	print(x)
	exit()
(n, m) = inpl()
a = inpl()
imo = [0] * (n + 2)
for i in range(m - 1):
	(l, r) = (a[i], a[i + 1])
	if l == r:
		continue
	if l > r:
		(l, r) = (r, l)
	X = r - l
	imo[1] += X
	imo[n + 1] -= X
	imo[l] += r - 1 - X
	imo[l + 1] -= r - 1 - X
	imo[r] += l - X
	imo[r + 1] -= l - X
	imo[l + 1] += -1
	imo[r] -= -1
imo = list(itertools.accumulate(imo))
print(*imo[1:n + 1])


(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)
for i in range(1, n + 1):
	foo[i] += foo[i - 1]
	print(foo[i], end=' ')
print()


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)
		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 os
from io import BytesIO, IOBase
import sys
from collections import deque

def main():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	c = [a[0]]
	for i in range(1, m):
		if a[i] != c[-1]:
			c.append(a[i])
	(a, m) = (c, len(c))
	b = [[] for _ in range(n + 1)]
	for (i, v) in enumerate(a):
		b[v].append(i + 1)
	a.insert(0, 0)
	pos = [i for i in range(n + 1)]
	z = 0
	for i in range(1, m):
		z += abs(pos[a[i]] - pos[a[i + 1]])
	ans = [z]
	for i in range(2, n + 1):
		for j in b[i - 1]:
			if j > 1:
				z -= abs(pos[a[j - 1]] - pos[i - 1])
			if j + 1 <= m:
				z -= abs(pos[a[j + 1]] - pos[i - 1])
		for j in b[i]:
			if j > 1 and a[j - 1] != i - 1:
				z -= abs(pos[a[j - 1]] - pos[i])
			if j + 1 <= m and a[j + 1] != i - 1:
				z -= abs(pos[a[j + 1]] - pos[i])
		(pos[i], pos[i - 1]) = (pos[i - 1], pos[i])
		for j in b[i - 1]:
			if j > 1:
				z += abs(pos[a[j - 1]] - pos[i - 1])
			if j + 1 <= m:
				z += abs(pos[a[j + 1]] - pos[i - 1])
		for j in b[i]:
			if j > 1 and a[j - 1] != i - 1:
				z += abs(pos[a[j - 1]] - pos[i])
			if j + 1 <= m and a[j + 1] != i - 1:
				z += abs(pos[a[j + 1]] - pos[i])
		ans.append(z)
	print(*ans)
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, 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)


from collections import defaultdict

def main():
	(n, m) = readIntArr()
	x = readIntArr()
	idxOf = defaultdict(lambda : [])
	for i in range(m):
		idxOf[x[i]].append(i)
	ans = []
	f = 0
	for i in range(m - 1):
		f += abs(x[i] - x[i + 1])
	ans.append(f)
	for i in range(2, n + 1):
		for j in idxOf[1]:
			if j - 1 >= 0:
				f -= abs(x[j - 1] - x[j])
			if j + 1 < m:
				f -= abs(x[j] - x[j + 1])
		for j in idxOf[i]:
			if j - 1 >= 0:
				f -= abs(x[j - 1] - x[j])
			if j + 1 < m:
				f -= abs(x[j] - x[j + 1])
		for j in idxOf[1]:
			x[j] = i
		for j in idxOf[i]:
			x[j] = 1
		temp = idxOf[1]
		idxOf[1] = idxOf[i]
		idxOf[i] = temp
		for j in idxOf[1]:
			if j - 1 >= 0:
				f += abs(x[j - 1] - x[j])
			if j + 1 < m:
				f += abs(x[j] - x[j + 1])
		for j in idxOf[i]:
			if j - 1 >= 0:
				f += abs(x[j - 1] - x[j])
			if j + 1 < m:
				f += abs(x[j] - x[j + 1])
		ans.append(f)
	oneLineArrayPrint(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


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


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]


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


(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 io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, m) = kk()
x = list(map(lambda x: int(x) - 1, input().split()))
diffirst = [0] * n
cntstart = [0] * n
cntend = [0] * n
total = 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
	d = b - a
	total += d
	diffirst[a] += b - d
	diffirst[b] += a - d + 1
	cntstart[a] += 1
	cntend[b] += 1
ls = []
for i in range(n):
	total += cntend[i]
	ls.append(total + diffirst[i])
	total -= cntstart[i]
print(' '.join(map(str, ls)))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.height = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val == 0:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
			elif val >= 1:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left

	def do(self, temp):
		if not temp:
			return 0
		ter = temp
		temp.height = self.do(ter.left) + self.do(ter.right)
		if temp.height == 0:
			temp.height += 1
		return temp.height

	def query(self, xor):
		self.temp = self.root
		cur = 0
		i = 31
		while i > -1:
			val = xor & 1 << i
			if not self.temp:
				return cur
			if val >= 1:
				self.opp = self.temp.right
				if self.temp.left:
					self.temp = self.temp.left
				else:
					return cur
			else:
				self.opp = self.temp.left
				if self.temp.right:
					self.temp = self.temp.right
				else:
					return cur
			if self.temp.height == pow(2, i):
				cur += 1 << i
				self.temp = self.opp
			i -= 1
		return cur
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
ans = [0] * (n + 1)
ans1 = [0] * (n + 1)
for i in range(1, m):
	if l[i] == l[i - 1]:
		continue
	k = abs(l[i] - l[i - 1])
	a = min(l[i], l[i - 1]) - 1
	b = max(l[i], l[i - 1]) - 1
	ans[a] += b
	ans[b] += a + 1
	ans1[a + 1] += k - 1
	ans1[b] -= k - 1
	ans1[0] += k
	ans1[a] -= k
	ans1[b + 1] += k
	ans1[n] -= k
for i in range(n):
	if i > 0:
		ans1[i] += ans1[i - 1]
	print(ans1[i] + ans[i], end=' ')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
x = list(map(int, input().split()))
s = 0
for i in range(m - 1):
	s += abs(x[i] - x[i + 1])
ans = [s] * n
y = [0] * n
for i in range(m - 1):
	(u, v) = (x[i] - 1, x[i + 1] - 1)
	if u == v:
		continue
	if u > v:
		(u, v) = (v, u)
	y[u + 1] -= 1
	y[v] += 1
	d = v - u
	ans[u] += u
	ans[v] += u + 1 - d
for i in range(1, n):
	y[i] += y[i - 1]
for i in range(n):
	ans[i] += y[i]
print(*ans)


def solver():
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	(xin, xout) = ([0] * (n + 10), [0] * (n + 10))
	xsum = [0] * (n + 10)
	xseg = [0] * (n + 10)
	ans = 0
	for i in range(1, len(s)):
		(b, a) = (max(s[i], s[i - 1]), min(s[i], s[i - 1]))
		if a == b:
			continue
		xin[a] += 1
		xout[b] += 1
		xsum[b] += a
		ans += abs(s[i] - s[i - 1])
	ret = 0
	for i in range(1, n + 1):
		ret -= xout[i]
		xseg[i] = ret
		ret += xin[i]
	for i in range(n):
		ret = ans
		i += 1
		if i == 1:
			print(ret)
			continue
		ret -= xseg[i]
		ret += -(i * xout[i] - 2 * xsum[i])
		ret += (i - 1) * xin[i]
		print(ret)

def main():
	while 1:
		try:
			solver()
		except EOFError:
			break
main()


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