CodeEff/ECCO huggingface dataset:
# Original solution
N = eval(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    if max(a, b, c) == b or min(a, b, c) == b:
        diff = - abs(a - b) - abs(b - c) + abs(a - c)
    else:
        diff = 0
    print(cost + diff)


# Optimized solution
N = eval(input())
A = [0] + list(map(int, input().split())) + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    print(cost - abs(a - b) - abs(b - c) + abs(a - c))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))

A.insert(0,0)
A.append(0)
_A = []

for i in range(1,N+1):
  _A.append(abs(A[i] - A[i-1]))
_A.append(abs(0-A[N]))
S = sum(_A)


for i in range(0,N):
  allS = sum(_A)
  allS -= (_A[i]+_A[i+1]-abs(A[i+2]-A[i]))
  print(allS)

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

A.insert(0,0)
A.append(0)
_A = []

for i in range(1,N+1):
  _A.append(abs(A[i] - A[i-1]))
_A.append(abs(0-A[N]))
S = sum(_A)


for i in range(0,N):
  allS = S
  allS -= (_A[i]+_A[i+1]-abs(A[i+2]-A[i]))
  print(allS)
# Original solution
N=int(eval(input()))
s= list(map(int,input().split()))
s.insert(0,0)
s.append(0)
for i in range(len(s)-2):
    tmp=s[:]
    del tmp[i+1]
    tmp_sum=0
    for i in range(len(tmp)-1):
        tmp_sum+=abs(tmp[i]-tmp[i+1])
    if i ==(len(tmp)-2):
        print(tmp_sum)

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

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

B = [0] + A + [0]
S = [0]*(N+2) 
for i in range(1, N+2):
    S[i] = S[i-1] + abs(B[i] - B[i-1])

max_s = S[-1]
for i in range(1, N+1):
    ans = 0
    ans += S[i-1]
    ans += abs(B[i-1]-B[i+1])
    ans += max_s - S[i+1]
    print(ans)


# Optimized solution
N = int(eval(input()))

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

B = [0] + A + [0]

diff_1 = [abs(B[i+1] - B[i]) for i in range(N+1)]
diff_2 = [abs(B[i+2] - B[i]) for i in range(N)]
ans = sum(diff_1)

for i in range(N):
    tmp = ans + diff_2[i] - (diff_1[i] + diff_1[i+1])
    print(tmp)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
for i in range(n):
    p = a[i + 1]
    del a[i + 1]
    ans = 0
    for j in range(len(a) - 1):
        ans += abs(a[j] - a[j + 1])
    a.insert(i + 1, p)
    print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
ans = 0
for j in range(len(a) - 1):
    ans += abs(a[j] - a[j + 1])
    
for i in range(n):
    p = abs(a[i + 2] - a[i])
    q = abs(a[i + 1] - a[i])
    r = abs(a[i + 1] - a[i + 2] )
    print((ans + p - q - r))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(a[i+1]-a[i])
b.append(-a[-1])
for i in range(n):
    k = 0
    for l in range(n+1):
        if l == i:
            k += abs(b[i]+b[i+1])
        elif l != i+1:
            k += abs(b[l])
    print(k)


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
a.append(0)
a.insert(0,0)
s = 0
for i in range(n+1):
    s += abs(a[i]-a[i+1])
for i in range(1,n+1):
    print((s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])))
# Original solution
if __name__ == '__main__':
    n = int(eval(input()))
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)
    
    sum = 0
    for i in range(n):
        root = list(A[:])
        del root[i+1]
        for j in range(1, n+1):
            sum += abs(root[j]-root[j-1])
        print(sum)
        sum = 0


# Optimized solution
if __name__ == '__main__':
    n = int(eval(input()))
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)

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

for i in range(n):
    ans = 0
    s = 0
    for j in range(n+1):
        if j != i:
            ans += abs(s-a[j])
            s = a[j]
    print(ans)

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

s = 0

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

for i in range(n):
    print((s+abs(a[i]-a[i+2])-(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2]))))
# Original solution
import copy

N = int(eval(input()))
As = list(map(int, input().split()))
As = [0] + As + [0]


def dist(a, b):
    return abs(a - b)


dAs = [dist(As[i], As[i+1]) for i in range(N+1)]


def rem(i):
    ret = copy.deepcopy(dAs)
    print(('copy', ret))
    ret[i] = dist(As[max(0, i-1)], As[i+1])
    print(('rett', ret, i))
    ret = ret[:max(0, i-1)] + ret[i:]
    print(('As', As))
    print(('ret', ret))
    return ret

def calc(i):
    return sum(dAs) - dist(As[i], As[i-1]) - dist(As[i+1], As[i]) + dist(As[i+1], As[i-1])


for i in range(1, N+1):
    print((calc(i)))


# Optimized solution
import copy
import time


N = int(eval(input()))
As = list(map(int, input().split()))
As = [0] + As + [0]

t0 = time.time()

def dist(a, b):
    return abs(a - b)


dAs = [dist(As[i], As[i+1]) for i in range(N+1)]
sumdAs = sum(dAs)
# print(time.time()-t0, 'a')

def rem(i):
    ret = copy.deepcopy(dAs)
    print(('copy', ret))
    ret[i] = dist(As[max(0, i-1)], As[i+1])
    print(('rett', ret, i))
    ret = ret[:max(0, i-1)] + ret[i:]
    print(('As', As))
    print(('ret', ret))
    return ret

def calc(i):
    return sumdAs - dist(As[i], As[i-1]) - dist(As[i+1], As[i]) + dist(As[i+1], As[i-1])


for i in range(1, N+1):
    print((calc(i)))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])+abs(A[N])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
for i in range(1,N+1):
    if i==1:
        print((tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2])))
    elif i==N:
        print((tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1])))
    else:
        print((tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = 0
for i in range(1,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[0]-A[N])
for i in range(1,N):
    a = tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
    print(a)
a = tot-abs(A[N]-A[N-1])-abs(0-A[N])+abs(0-A[N-1])
print(a)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = 0
for i in range(1,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[0]-A[N])
for i in range(1,N):
    a = tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
    print(a)
a = tot-abs(A[N]-A[N-1])-abs(0-A[N])+abs(0-A[N-1])
print(a)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
print((tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2])))
for i in range(2,N):
    print((tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])))
print((tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1])))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
for i in range(1,N+1):
    if i==1:
        print((tot-abs(A[1])-abs(A[2]-A[1])+abs(A[2])))
    elif i==N:
        print((tot-abs(A[N])-abs(A[N]-A[N-1])+abs(A[N-1])))
    else:
        print((tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
tot = abs(A[1])
for i in range(2,N+1):
    tot += abs(A[i]-A[i-1])
tot += abs(A[N])
for i in range(1,N):
    a = tot-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
    print(a)
a = tot-abs(A[N]-A[N-1])-abs(A[N])+abs(A[N-1])
print(a)
# Original solution
import copy

n = int(eval(input()))

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

#print(a)


for i in range(1,len(a)-1):
    ans = 0
    for j in range(1,len(a)):
        if(j-1 != i and j != i):
            ans += abs(a[j]-a[j-1])
        elif(j == i):
            ans += abs(a[j+1]-a[j-1])
            j+=1
    print(ans)

    

# Optimized solution
import copy

n = int(eval(input()))

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

#print(a)
anst = 0
for j in range(1,len(a)):
    anst += abs(a[j]-a[j-1])

for j in range(1,len(a)-1):
    ans = anst
    ans -= abs(a[j-1]-a[j]) + abs(a[j]-a[j+1])
    ans += abs(a[j-1]-a[j+1])
    print(ans)
# Original solution
import fractions
from functools import reduce
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
for n in range(N):
    path = [0]+A[0:n]+A[n+1:]+[0]
    print((sum(abs(path[i]-path[i-1]) for i, _ in enumerate(path))))

# Optimized solution
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0]+[int(_) for _ in stdin.readline().rstrip().split()]+[0]
S = sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print((S-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()))
A = list(map(int, input().split()))
A = [0] + A  + [0]
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
for i in range(N):
  ans = sum(cost) - cost[i] - cost[i+1]
  ans += abs(A[i]-A[i+2])
  print(ans)

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

a.append(0)

for i in range(n):
    cost=0
    pv=0
    nx=0
    for j in range(len(a)):
        if i == j:
            continue
        pv, nx = nx, a[j]
        cost+=abs(pv-nx)

    print(cost)


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

a=[0]+a+[0]

cost=[abs(a[i]-a[i+1]) for i in range(len(a)-1)]
total=sum(cost)

ans=0
for i in range(n):
    ans = total - cost[i] - cost[i+1] + abs(a[i+2]-a[i])
    print(ans)
# Original solution
def cs(x):
    ans = 0
    for i in range(len(x)-1):
        ans += abs(x[i+1]-x[i])
    return ans


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

for i in range(1, len(a)-1):
    print((cs(a[:i] + a[i+1:])))

# Optimized solution
def cs(x):
    ans = 0
    for i in range(len(x)-1):
        ans += abs(x[i+1]-x[i])
    return ans


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

s = cs(a)

for i in range(1, len(a)-1):
    dif = abs(a[i]-a[i-1]) + abs(a[i+1]-a[i]) - abs(a[i+1]-a[i-1])
    print((s-dif))
# Original solution
n = int(eval(input()))
tmpa = list(map(int, input().split()))
A = [0] * (n+2)
A[0] = 0
A[n+1] = 0
for i in range(1,n+1,1): A[i] = tmpa[i-1]


#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


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

#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)
# Original solution
N = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(N + 1):
    total += abs(A[i + 1] - A[i])
for i in range(N):
    print((total + abs(A[i + 2] - A[i]) - (abs(A[i + 1] - A[i] ) + abs(A[i + 2] - A[i + 1]))))


# Optimized solution
N, *A = list(map(int, open(0).read().split()))

A = [0] + A + [0]

acc = [0] * (N + 2)
for i in range(N + 1):
    acc[i + 1] = acc[i] + abs(A[i + 1] - A[i])

for i in range(N):
    left = acc[i] - acc[0]
    right = acc[N + 1] - acc[i + 2]
    print((left + abs(A[i + 2] - A[i]) + right))
# Original solution
n=int(eval(input()))
l=[0]+list(map(int,input().split()))+[0]
ans=0
for a,s in zip(l,l[1:]):
    ans+=abs(a-s)
for i in range(n):
    a,s=sorted([l[i],l[i+2]])
    if a<=l[i+1]<=s:print(ans)
    else:
        print((ans-abs(a-l[i+1])-abs(l[i+1]-s)+s-a))

# Optimized solution
n=eval(input())
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print((ans if l[i+1]<l[i] else ans+dif))
  else:print((ans if l[i+1]>l[i] else ans+dif))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
s = 0
a.insert(0, 0)
a.insert(n + 1, 0)
for i in range(1, n + 2):
    s += abs(a[i - 1] - a[i])
for i in range(1, n + 1):
    print((s - (abs(a[i - 1] - a[i]) + 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]
s = 0
for i in range(1, n + 2):
    s += abs(a[i] - a[i - 1])
for i in range(1, n + 1):
    print((s - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1])))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.append(0)
for i in range(N):
    ans = 0
    tmp = 0
    for index, a in enumerate(A):
        if i != index:
            ans += abs(tmp-a)
            tmp = a
    print(ans)

# Optimized solution
N = int(eval(input()))
A = [0]
A = A + list(map(int, input().split()))
A.append(0)
sumOfRoute = 0
tmp = 0
for a in A:
    sumOfRoute += abs(tmp-a)
    tmp = a

prev = 0
for i in range(1, N+1):
    nexti = A[i+1]
    print((sumOfRoute + abs(prev - nexti) - abs(A[i] - nexti) - abs(prev - A[i])))
    prev = A[i]
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
L = []
A.insert(0,0)
A.insert(N+1,0)
for i in range(1,N+1):
  k = 0
  L.append(A[i])
  del (A[i])
  for j in range(N):
    k += abs(A[j]-A[j+1])
  A.insert(i,L[i-1])
  print(k)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
A.insert(N+1,0)
S = 0
for i in range(N+1):
  S += abs(A[i]-A[i+1])
for i in range(1,N+1):
  print((S-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1])))
# Original solution
#!/usr/bin/env python3

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n):
        fix = [0] + a[0:i] + a[i + 1:n] + [0]
        ans[i] = sum([abs(fix[j] - fix[j - 1]) for j in range(1, n + 1)])
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3

def main():
    n = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    dist = [abs(a[i] - a[i - 1]) for i in range(1, n + 2)]
    total = sum(dist)
    ans = [0] * n
    for i in range(n):
        ans[i] = total - dist[i] - dist[i + 1] + abs(a[i] - a[i + 2])
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]

dist = 0
for x, y in zip(A[:-1], A[1:]):
    dist += abs(x - y)

for i in range(1, N + 1):
    l, m, r = A[i - 1], A[i], A[i + 1]
    d = dist
    d -= abs(l - m)
    d -= abs(r - m)
    d += abs(r - l)
    print(d)

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

d = [x - y for y, x in zip(A[:-1], A[1:])]
dist = sum(abs(i) for i in d)

for i in range(N):
    ans = dist - abs(d[i]) - abs(d[i + 1])
    ans += abs(A[i] - A[i + 2])
    print(ans)
# Original solution
import collections
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
m=[]
m2=[0]
for i in range(n):
  m.append(a[i])
for i in range(n):
  m2.append((m2[-1]+m[i]))
for i in range(n+1):
  m2[i]-=i
  m2[i]%=k

ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
  x=m2[i]
  if i<=k-1:
    dict[m2[i-1]]+=1
  else:
    dict[m2[i-1]]+=1
    dict[m2[i-k]]-=1
  ans+=dict[x]
print(ans)

# Optimized solution
import collections
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
m=[0]
for i in range(n):
  m.append((m[-1]+a[i]))
for i in range(n+1):
  m[i]-=i
  m[i]%=k

ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
  x=m[i]
  if i<=k-1:
    dict[m[i-1]]+=1
  else:
    dict[m[i-1]]+=1
    dict[m[i-k]]-=1
  ans+=dict[x]
print(ans)
# Original solution
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + A[i - 1] - 1
    acc[i] %= K

mp = defaultdict(int)
ans = 0
q = deque([])
for j in range(N + 1):
    ans += mp[acc[j]]
    mp[acc[j]] += 1
    q.append(acc[j])
    if len(q) == K:
        mp[q[0]] -= 1
        q.popleft()
print(ans)

# Optimized solution
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

acc = [0] * (N + 1)
for i in range(1, N + 1):
    acc[i] = acc[i - 1] + A[i - 1] - 1
    acc[i] %= K

mp = defaultdict(int)
ans = 0
for j in range(N + 1):
    if j >= K:
        mp[acc[j - K]] -= 1
    ans += mp[acc[j]]
    mp[acc[j]] += 1
print(ans)
# Original solution
N,K=list(map(int,input().split()))
A=[int(i) for i in input().split()]

# 2D dynamic programming solution?
dp = [[0]*(N) for i in range(N)]
dp[0] = A

num_seq = 0

for a in A:
    if (a % K) == 1:
        num_seq += 1

for i in range(1, len(A)):
    for j in range(1,i+1):
        if j == 1:
            subseq_total = sum(A[i-j:i+1])
            dp[j][i] = subseq_total
        else:
            subseq_total = dp[j-1][i-1] + A[i]
        dp[j][i] = subseq_total
        if (subseq_total % K) == (j+1):
            num_seq += 1

#for row in dp:
#    print(row)

print(num_seq)


# Optimized solution
N,K=list(map(int,input().split()))
A=[int(i) for i in input().split()]

# 2D dynamic programming solution using 2 rows
dp = [[0]*(N) for i in range(2)]
dp[0] = A

num_seq = 0

for a in A:
    if (a % K) == 1:
        num_seq += 1

# pass through a single row first
for i in range(1, N): # i = row
    for j in range(i, N): # j = col
        if i == 1:
            subseq_total = sum(A[j-1:j+1])
        else:
            subseq_total = dp[0][j-1] + A[j]
        dp[1][j] = subseq_total
        if (subseq_total % K) == (i+1):
            num_seq += 1
    dp[0] = dp[1]
    dp[1] = [0]*N

#for row in dp:
#    print(row)

print(num_seq)
# Original solution
from collections import defaultdict
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      list(map(int, input().split()))
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
h =defaultdict(int)
b = [0]*(n+1)
s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i]+a[i]
    b[i+1] = (s[i+1]-i-1)%k
ddprint(s)
ddprint(b)
acc = 0
for i in range(n+1):
    if i>=k:
        h[b[i-k]] -= 1
    acc += h[b[i]]
    h[b[i]] += 1
    ddprint("i {} acc {} h {}".format(i,acc,h))
print(acc)


# Optimized solution
from collections import defaultdict
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      list(map(int, input().split()))
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
a = inl()
h =defaultdict(int)
b = [0]*(n+1)
s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i]+a[i]
    b[i+1] = (s[i+1]-i-1)%k
ddprint(s)
ddprint(b)
acc = 0
for i in range(n+1):
    if i>=k:
        h[b[i-k]] -= 1
    acc += h[b[i]]
    h[b[i]] += 1
    #ddprint("i {} acc {} h {}".format(i,acc,h))
print(acc)
# Original solution
from itertools import accumulate
from collections import Counter, defaultdict
import copy
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + list(accumulate([(i-1) % k for i in a]))
a = [i % k for i in a]
ans = 0
start = defaultdict(int)
start[0] += 1
maps = [start]
for i in a[1:]:
  now = maps[-1].copy()
  now[i] += 1
  maps.append(now)
for i in range(n):
  v = a[i]
  ans += maps[min(n,i+k-1)][v]-maps[i][v]
print(ans)

# Optimized solution
from itertools import accumulate
from collections import defaultdict
import bisect

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + list(accumulate([(i-1) % k for i in a]))
a = [i % k for i in a]
ans = 0
maps = defaultdict(list)
for k1,v in enumerate(a):
  maps[v].append(k1)
for i in range(n):
  v = a[i]
  ans += bisect.bisect_right(maps[v],i+k-1) - bisect.bisect_right(maps[v],i)
print(ans)
# Original solution
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = list(map(int, input().split()))

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

s = list(accumulate([0]+a))

b = [s[i]-i for i in range(n+1)]

d = defaultdict(list)

for i in range(n+1):
    d[b[i]%k].append(i)

ans = 0
for x in list(d.keys()):
    l = d[x]
    for j in range(len(l)):
        y = l[j]
        ans += max(0,bisect.bisect_right(l,k+y-1)-j-1)

print(ans)




# Optimized solution
from collections import defaultdict
from itertools import accumulate

n,k = list(map(int, input().split()))

a = list(map(int,input().split()))
s = list(accumulate([0]+a))
b = [(s[i]-i)%k for i in range(n+1)]

d = defaultdict(int)
# 初期化
for i in range(min(k-1,n+1)):
    d[b[i]]+=1

ans = 0
for i in range(n):
    # 自分を除外し、k-1個先が存在すれば加える。
    d[b[i]]-=1
    if i+k-1<=n:
        d[b[i+k-1]]+=1
    ans += d[b[i]]

print(ans)