CodeEff/ECCO huggingface dataset:
# Original solution
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

n,k=MI()
a=LI()

def slidmin(a,k):
    n=len(a)
    b=[0 for i in range(n-k+1)]
    q=deque()
    for i in range(k):
        while q and a[q[-1]]>=a[i]:
            q.pop()
        q.append(i)
    b[0]=a[q[0]]
    s=len(q)
    for i in range(k,n):
        while q and a[q[-1]]>=a[i]:
            q.pop()
            s-=1
        q.append(i)
        s+=1
        if q[0]<=i-k:
            q.popleft()
            s-=1
        b[i-k+1]=a[q[0]]
    return b

m=slidmin(a,k)
M=[-i for i in slidmin([-i for i in a],k)]
ans=1
p=-1
c=0
for i in range(k):
    if p<a[i]:
        c+=1
    else:
        c=1
    p=a[i]
fl=True if c==k else False

for i in range(n-k):
    if p<a[i+k]:
        c+=1
    else:
        c=1
    p=a[i+k]
    
    inc=1
    if c==k:
        if fl:
            inc=0
        fl=True
    if a[i]==m[i] and a[i+k]==M[i+1]:
        inc=0
    ans+=inc
print(ans)


# Optimized solution
from collections import deque

def MI():
    return list(map(int,input().split()))
def LI():
    return [int(i) for i in input().split()]

n,k=MI()
a=LI()

def slidmin(a,k):
    n=len(a)
    b=[0 for i in range(n-k+1)]
    q=deque()
    for i in range(k):
        while q and a[q[-1]]>=a[i]:
            q.pop()
        q.append(i)
    b[0]=a[q[0]]
    s=len(q)
    for i in range(k,n):
        while q and a[q[-1]]>=a[i]:
            q.pop()
            s-=1
        q.append(i)
        s+=1
        if q[0]<=i-k:
            q.popleft()
            s-=1
        b[i-k+1]=a[q[0]]
    return b

m=slidmin(a,k)
M=[-i for i in slidmin([-i for i in a],k)]
ans=1
p=-1
c=0
for i in range(k):
    if p<a[i]:
        c+=1
    else:
        c=1
    p=a[i]
fl=True if c==k else False

for i in range(n-k):
    if p<a[i+k]:
        c+=1
    else:
        c=1
    p=a[i+k]
    
    inc=1
    if c==k:
        if fl:
            inc=0
        fl=True
    if a[i]==m[i] and a[i+k]==M[i+1]:
        inc=0
    ans+=inc
print(ans)
# Original solution
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))

#スライド最小値、スライド最大値
from collections import deque
def slide_max_index(a, K):
    # max_idx[i]: 区間 [i - K + 1, i] (両側閉区間)における a の最大値を与えるインデックス
    N = len(a)
    max_idx = [0] * N # (長さKに満たない左側領域もついでに計算する)
    deq = deque() # デック．番長順番待ちキューをシミュレートする．インデックスを格納しておく
    for i in range(0,N):
        while len(deq) > 0 and deq[0] <= i - K : deq.popleft() # 卒業する
        while len(deq) > 0 and a[deq[-1]] < a[i] : deq.pop()   # a[i] の入学で 望みがなくなった先輩達が脱落する
        deq.append(i)                                          # 新入生i は常に番長になる望みがある
        max_idx[i] = deq[0]                                    # 番長順番待ちキューの最左が番長
    return max_idx
def slide_min_index(a, K):
    # max_idx[i]: 区間 [i - K + 1, i] (両側閉区間)における a の最大値を与えるインデックス
    N = len(a)
    min_idx = [0] * N # (長さKに満たない左側領域もついでに計算する)
    deq = deque() # デック．番長順番待ちキューをシミュレートする．インデックスを格納しておく
    for i in range(0,N):
        while len(deq) > 0 and deq[0] <= i - K : deq.popleft() # 卒業する
        while len(deq) > 0 and a[deq[-1]] > a[i] : deq.pop()   # a[i] の入学で 望みがなくなった先輩達が脱落する
        deq.append(i)                                          # 新入生i は常に番長になる望みがある
        min_idx[i] = deq[0]                                    # 番長順番待ちキューの最左が番長
    return min_idx

min_idx=slide_min_index(p,k+1)
max_idx=slide_max_index(p,k+1)
eq=list(range(n-k+1))
for i in range(n-(k+1)+1):
  if i==min_idx[i+k] and i+k==max_idx[i+k]:
    eq[i+1]=eq[i]

pre=p[0]
a=[0]
c=0
for pi in p[1:]:
  if pre<pi:
    c+=1
  else:
    c=0
  pre=pi
  a.append(c)
eqi=-1
for i in range(n-k+1):
  if a[i+k-1]>=k-1:
    if eqi==-1:
      eqi=i
    else:
      eq[i]=eqi

print((len(set(eq))))
#print(eq)
#print(a)


# Optimized solution
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
from heapq import heappop,heappush,heapify


import heapq
class pqheap:
  def __init__(self,key=None):
    self.p = list()
    self.q = list()

  def insert(self,x):
    heapq.heappush(self.p, x)
    return

  def erase(self,x):
    heapq.heappush(self.q, x)
    return

  def minimum(self):
    while self.q and self.p[0] == self.q[0]:
      heapq.heappop(self.p)
      heapq.heappop(self.q)
    return self.p[0] if len(self.p)>0 else None
minheap=pqheap()
maxheap=pqheap()
for i in range(k):
  minheap.insert(p[i])
  maxheap.insert(-p[i])
ans=1
premin=minheap.minimum()
premax=-maxheap.minimum()

for i in range(k,n):
  ins=p[i]
  era=p[i-k]
  minheap.erase(era)
  maxheap.erase(-era)
  minheap.insert(ins)
  maxheap.insert(-ins)
  if premin==era and ins==-maxheap.minimum():
    pass
  else:
    ans+=1
  premax=-maxheap.minimum()
  premin=minheap.minimum()
ans0=0
now=1
pre=p[0]
for x in p[1:]:
  if x>pre:
    now+=1
  else:
    now=1
  if now==k:
    ans0+=1
  pre=x


print((ans-max(0,ans0-1)))
# Original solution
def main():
  def update(k,x):
    k+=N0-1
    data_min[k]=data_max[k]=x
    while k>=0:
      k=(k-1)//2
      a,b=data_min[2*k+1],data_min[2*k+2]
      data_min[k]=a if a<b else b
      a,b=data_max[2*k+1],data_max[2*k+2]
      data_max[k]=a if a>b else b
  def query_min(l,r):
    L,R=l+N0,r+N0
    s=INF
    while L<R:
      if R&1:
        R-=1
        t=data_min[R-1]
        if t<s:s=t
      if L&1:
        t=data_min[L-1]
        if t<s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def query_max(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
      if R&1:
        R-=1
        t=data_max[R-1]
        if t>s:s=t
      if L&1:
        t=data_max[L-1]
        if t>s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def root(x):
    while table[x]>=0:x=table[x]
    return x
  def unite(x,y):
    x=root(x)
    y=root(y)
    if x!=y:
      if table[x]>table[y]:x,y=y,x
      table[x]+=table[y]
      table[y]=x
  def same(x,y):return root(x)==root(y)
  def size(x):return-table[root(x)]
  n,k,*p=list(map(int,open(0).read().split()))
  N0=2**(n-1).bit_length()
  INF=10**18
  data_min=[INF]*2*N0
  data_max=[0]*2*N0
  table=[-1]*n
  c=[0]
  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
  x=not f
  for i,q in enumerate(p):update(i,q)
  for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1
  print((x+f))
main()

# Optimized solution
def main():
  def update(k,x):
    k+=N0-1
    data_min[k]=data_max[k]=x
    while k>=0:
      k=(k-1)//2
      a,b=data_min[2*k+1],data_min[2*k+2]
      data_min[k]=a if a<b else b
      a,b=data_max[2*k+1],data_max[2*k+2]
      data_max[k]=a if a>b else b
  def query_min(l,r):
    L,R=l+N0,r+N0
    s=INF
    while L<R:
      if R&1:
        R-=1
        t=data_min[R-1]
        if t<s:s=t
      if L&1:
        t=data_min[L-1]
        if t<s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def query_max(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
      if R&1:
        R-=1
        t=data_max[R-1]
        if t>s:s=t
      if L&1:
        t=data_max[L-1]
        if t>s:s=t
        L+=1
      L//=2
      R//=2
    return s
  n,k,*p=list(map(int,open(0).read().split()))
  N0=2**(n-1).bit_length()
  INF=10**18
  data_min=[INF]*2*N0
  data_max=[0]*2*N0
  c=[0]
  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
  x=not f
  for i,q in enumerate(p):update(i,q)
  for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1
  print((x+f))
main()
# Original solution
class SWAG():
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        *_,=list(map(self.append,data[sep:]))
        *_,=list(map(self.appendleft,data[sep-1::-1]))
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__init__(self.unit,self.f,self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__init__(self.unit,self.f,self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=list(map(int,open(0).read().split()))
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print((x+f))

# Optimized solution
class SWAG():
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        list(map(self.append,data[sep:]))
        list(map(self.appendleft,data[sep-1::-1]))
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__init__(self.unit,self.f,self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__init__(self.unit,self.f,self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=list(map(int,open(0).read().split()))
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print((x+f))
# Original solution
class SWAG():
    __slots__=('unit','f','fold_r','fold_l','data_r','data_l')
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        for t in data[sep:]:
            self.append(t)
        for t in data[sep-1::-1]:
            self.appendleft(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__init__(self.unit,self.f,self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__init__(self.unit,self.f,self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=list(map(int,open(0).read().split()))
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print((x+f))

# Optimized solution
class SWAG():
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.construct(data)
    def construct(self,data):
        self.fold_r=[self.unit]
        self.fold_l=[self.unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        for t in data[sep:]:
            self.append(t)
        for t in data[sep-1::-1]:
            self.appendleft(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.construct(self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.construct(self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=list(map(int,open(0).read().split()))
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print((x+f))
# Original solution
import copy

n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
l_list = []
ans = 1

tmp = copy.deepcopy(p)

l = tmp[:3]
l.sort()
l_list.append(l+tmp[3:])

for i in range(1,n-2):
	l = tmp[i:i+3]
	l.sort()
	l_list.append(tmp[:i] + l + tmp[i+3:])

	if l_list[i-1] == l_list[i]:
		continue
	else:
		ans += 1

print(ans)


# Optimized solution
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))

#リストを文字列化する方法
#''.join(map(str,p))

num_list = []
ans = 0

for i in range(n-k+1):
	tmp = p[i:i+k]
	tmp.sort()
	string1 = ''.join(map(str,p[:i]))
	string2 = ''.join(map(str,tmp))
	string3 = ''.join(map(str,p[i+k:]))
	string = string1+string2+string3
	if string not in num_list:
		num_list.append(string)
		ans += 1

print(ans)
# Original solution
NN = 18
MA = [-1] * ((1<<NN+1)-1)
MI = [1<<100] * ((1<<NN+1)-1)
 
def update(a, x):
    i = (1<<NN) - 1 + a
    MI[i] = x
    MA[i] = x
    while True:
        i = (i-1) // 2
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])
        if i == 0:
            break
def rangemin(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    mi = 1<<100
    while l < r:
        if l%2:
            mi = min(mi, MI[l-1])
            l += 1
        if r%2:
            r -= 1
            mi = min(mi, MI[r-1])
        l >>= 1
        r >>= 1
    return mi
def rangemax(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    ma = -1
    while l < r:
        if l%2:
            ma = max(ma, MA[l-1])
            l += 1
        if r%2:
            r -= 1
            ma = max(ma, MA[r-1])
        l >>= 1
        r >>= 1
    return ma

N, K = list(map(int, input().split()))
A = [int(a) for a in input().split()]
a = 0
l = -1
cnt = 0
for i in range(1, N):
    if A[i-1] > A[i]:
        a = i
    if i >= K-1 and a <= i - K + 1:
        if i - l > 1:
            cnt += 1
        l = i
ans = 1 - max(cnt-1, 0)
for i in range(N):
    update(i, A[i])
    if i >= K:
        mi = rangemin(i-K, i)
        ma = rangemax(i-K+1, i+1)
        if mi != A[i-K] or ma != A[i]:
            ans += 1

print(ans)

# Optimized solution
from collections import deque
def slidemax(X, k):
    q = deque([])
    ret = []
    for i in range(len(X)):
        while q and q[-1][1] <= X[i]:
            q.pop()
        deque.append(q, (i+k, X[i]))
        if q[0][0] == i:
            deque.popleft(q)
        if i >= k-1:
            ret.append(q[0][1])
    return ret

def slidemin(X, k):
    q = deque([])
    ret = []
    for i in range(len(X)):
        while q and q[-1][1] >= X[i]:
            q.pop()
        deque.append(q, (i+k, X[i]))
        if q[0][0] == i:
            deque.popleft(q)
        if i >= k-1:
            ret.append(q[0][1])
    return ret

N, K = list(map(int, input().split()))
A = [int(a) for a in input().split()]

a = 0
l = -1
cnt = 0
for i in range(1, N):
    if A[i-1] > A[i]: a = i
    if i >= K-1 and a <= i - K + 1:
        if i - l > 1: cnt += 1
        l = i

MA = slidemax(A, K)
MI = slidemin(A, K)
ans = 1 - max(cnt-1, 0)
l = -1
for i in range(K, N):
    if MI[i-K] != A[i-K] or MA[i-K+1] != A[i]:
        ans += 1

print(ans)
# Original solution
n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))

from collections import deque
def slide_max(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x < l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs

def slide_min(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x > l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs

maxs, mins = slide_max(k, xs), slide_min(k, xs)
aa, bb = xs[:k], xs[k:]

b, nb, bx = aa[0], aa[1], aa[-1]
ba = None
c = 1
for a in aa:
    if ba == None:
        ba = a
        continue
    if a > ba:
        c += 1
    else:
        c = 1
    ba = a

rok = False
if c == k:
    rok = True

r = 1
bs = xs[0]
for i, (s, x) in enumerate(zip(xs[1:], bb)):

    if x > bx:
        c = min(c+1, k)
    else:
        c = 1
    bx = x

    if c == k:
        if not rok:
            r += 1
        rok = True
        continue

    if x != maxs[i+1]: 
        r+=1
    elif bs != mins[i]:
        r+=1
    bs = s

print(r)


# Optimized solution
n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))
from collections import deque
def slide_max(k, l):
    rs, rrs = [], set()
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x < l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs

def slide_min(k, l):
    rs = []
    rrs = set()
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x > l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i+1 < k:
            continue
        if len(dq) == k:
            rrs.add(i+1-k)
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs, rrs

maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs)
r = 1
for i, (s, x) in enumerate(zip(xs, xs[k:])):
    if (x != maxs[i+1] or s != mins[i]) and (i+1 not in ns): 
        r+=1
if (0 not in ns) and (len(ns) > 0):
    r += 1
print(r)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a = [0] + a + [0]
sa = []
for i in range(n+1):
    sa.append(abs(a[i]-a[i+1]))

for i in range(1, n+1):
    print((sum(sa) - sa[i-1] - sa[i] + abs(a[i-1]-a[i+1])))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a = [0] + a + [0]
sa = 0
for i in range(n+1):
    sa += abs(a[i]-a[i+1])

for i in range(1, n+1):
    print((sa - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])) + abs(a[i-1]-a[i+1])))
# Original solution
n = int(eval(input()))
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])

for i in range(0,n):
    ans = 0
    for j in range(0,n+1):
        if j != i and j != i + 1:
            ans += abs(list_memo[j])
    ans += abs(list_memo[i+1] + list_memo[i])
    print(ans)


# Optimized solution
n = int(eval(input()))
list_a = list(map(int, input().split()))
list_memo = []
for i in range(0,n):
    if i == 0:
        list_memo.append(list_a[i])
    else:
        list_memo.append(list_a[i]-list_a[i-1])
list_memo.append(-list_a[n-1])
ans_pre = 0
for i in range(0,n+1):
    ans_pre += abs(list_memo[i])
for i in range(0,n):
    ans = ans_pre - abs(list_memo[i]) - abs(list_memo[i+1]) + abs(list_memo[i] + list_memo[i+1])
    print(ans)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
ans = [-1]*n
A = [0]+A+[0]
s = 0
for i in range(1, n+2):
    s += abs(A[i]-A[i-1])
#print(s)
for i in range(n):
    temp = s
    temp -= abs(A[i+1]-A[i])
    temp -= abs(A[i+2]-A[i+1])
    temp += abs(A[i+2]-A[i])
    ans[i] = temp
for i in range(n):
    print((ans[i]))


# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))

A = [0]+A+[0]

s = 0
for i in range(1, n+2):
    s += abs(A[i]-A[i-1])

for i in range(1, n+1):
    ans = s
    ans -= abs(A[i]-A[i-1])
    ans -= abs(A[i+1]-A[i])
    ans += abs(A[i+1]-A[i-1])
    print(ans)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

A = [0]+A+[0]

s = 0
for i in range(1, n+2):
    s += abs(A[i]-A[i-1])

for i in range(1, n+1):
    ans = s
    ans -= abs(A[i]-A[i-1])
    ans -= abs(A[i+1]-A[i])
    ans += abs(A[i+1]-A[i-1])
    print(ans)


# Optimized solution
n = int(input())
A = list(map(int, input().split()))
res = 0
pre = 0
for a in A:
    res += abs(a-pre)
    pre = a
else:
    res += abs(0-pre)

#print(res)
ans = [0]*n
A = [0]+A+[0]
for i in range(n):
    j = i+1
    temp = res-abs(A[j-1]-A[j])-abs(A[j+1]-A[j])+abs(A[j+1]-A[j-1])
    ans[i] = temp
print(*ans, sep='\n')
# Original solution
from operator import itemgetter

n = int(eval(input()))
a = [0] + list(map(int, input().split())) + [0]

sougaku = 0
for i in range(n + 1):
	sougaku += abs(a[i] - a[i + 1])

for i in range(1, n + 1):
	print((sougaku - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])))

# Optimized solution
n = int(eval(input()))
a = [0] + list(map(int, input().split())) + [0]

sougaku = 0
for i in range(n + 1):
	sougaku += abs(a[i] - a[i + 1])

for i in range(1, n + 1):
	print((sougaku - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1])))
# Original solution
def run(lst, i):
    lst = [0]+lst+[0]
    cost = 0
    a = lst[:i]+lst[i+1:]
    for a,b in zip(a,a[1:]):
        cost+=abs(b-a)
    return cost

N = int(eval(input()))
l = list(map(int,input().split()))
for i in range(1,N+1):
    print((run(l,i)))


# Optimized solution
N = int(eval(input()))
l = list(map(int,input().split()))
l = [0]+l+[0]
cost = 0
for a,b in zip(l,l[1:]):
    cost += abs(b-a)
for i in range(1,N+1):
    n = cost
    n-=abs(l[i-1]-l[i])
    n-=abs(l[i]-l[i+1])
    n+=abs(l[i-1]-l[i+1])
    print(n)
# Original solution
n = int(eval(input()))
a = [0] +list(map(int, input().split()))+[0]
money = [0]
for i in range(n+1):
  money.append(abs(a[i]-a[i+1]))

ans = sum(money)
for i in range(n):
  print((ans-sum(money[i+1:i+3])+abs(a[i]-a[i+2])))

# Optimized solution
n = int(eval(input()))
A = [0]+ list(map(int, input().split())) + [0]
a = [0]
for i in range(1,n+2):
    a.append(abs(A[i-1]-A[i]))
ans = sum(a)
for i in range(1,n+1):
    x = ans - a[i] - a[i+1]
    x += abs(A[i-1]-A[i+1])
    print(x)