Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    # for i in S:
    #     cnt[i % 2019] += 1

    ans = 0

    for i in cnt:
        ans += i * (i - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, 2019)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    # for i in S:
    #     cnt[i % 2019] += 1

    ans = 0

    for i in cnt:
        ans += i * (i - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=-a[i]

for i in range(m):
    heapq.heapify(a)
    heapq.heappush(a,-(-heapq.heappop(a)//2))

print(-sum(a))


### FIXED CODE ###

import sys
input = sys.stdin.readline
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=-a[i]

heapq.heapify(a)
for i in range(m):
    c=-(-heapq.heappop(a)//2)
    heapq.heappush(a,c)
#print(a)
print(-sum(a))
### BUGGY CODE ###

import bisect
n,m=map(int, input().split())
l={}
for i in range(n):
    a,b=map(int, input().split())
    if not a in l:
        l[a]=[b]
    else:
        l[a].append(b)

res=0
target=[0]*m
for i in range(1,m+1):
    if i in l:
        for j in l[i]:
            bisect.insort_left(target, j)
    val=target.pop()
    res+=val
    #print(target, max(target))

print(res)




### FIXED CODE ###

import bisect
import array

n,m=map(int, input().split())
l={}
for i in range(n):
    a,b=map(int, input().split())
    if not a in l:
        l[a]=[b]
    else:
        l[a].append(b)

res=0
target=array.array('I', [])
for i in range(1,m+1):
    if i in l:
        for j in l[i]:
            bisect.insort_left(target, j)

    if not target:
        val=0
    else:
        val=target.pop()
    res+=val
    #print(target, max(target))

print(res)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

BClist = []
for i in range(N):
    for j in range(N):
        if(B[i] < C[j]):
            BClist.append(N-j)
            break

ans = 0
for k in range(N):
    for i in range(N):
        if(A[k] < B[i]):
            ans += sum(BClist[i:])
            break

print(ans)

### FIXED CODE ###

import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
a.sort()
b.sort()
c.sort()

for j in range(n):
    ans += bisect.bisect_left(a,b[j])*(n-bisect.bisect_right(c,b[j]))
print(ans)
### BUGGY CODE ###

a, b, c, kk = map(int, input().split())

ans = 0
for k in range(kk):
    if a:
        ans += 1
        a -= 1

    elif b:
        b -= 1

    elif c:
        ans -= 1
        c -= 1

print(ans)


### FIXED CODE ###

a, b, c, k = map(int, input().split())

ans = 0
if a < k:
    ans = a
else:
    ans = k

minus = k - (a + b)

if minus > 0:
    ans -= minus

print(ans)
### BUGGY CODE ###

#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())

N,Ma,Mb=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(N)]
idle_max=10**9
dp=[[idle_max for m in range(2**(N+1))] for i in range(N)]

dp[0][1]=ABC[0][2]

for n in range(1,N):
    a,b,c=ABC[n]
    for i in range(2**(N+1)):
        if i|2**n<len(dp[0]):
            dp[n][i|2**n]=min(dp[n-1][i]+c,dp[n-1][i|2**n],dp[n][i])
        dp[n][i]=min(dp[n-1][i],dp[n][i])
value=idle_max

for i in range(len(dp[0])):
    A=0;B=0
    for n in range(N):
        a,b,c=ABC[n]
        if (i>>n)&1:
            A+=a
            B+=b
    Z=gcd(A,B)
    if A and B and Ma==A//Z and Mb==B//Z:
        value=min(value,dp[-1][i])
if value!=idle_max:
    print(value)
else:
    print(-1)


### FIXED CODE ###

#import decimal
#decimal.getcontext().prec==500 Floatの桁数を500まで増やす
#Decimal(c).sqrt() それで平方根を求める
#Decimal(1) / Decimal(7) 1/7
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
#input = sys.stdin.readline


#N=int(input())

N,Ma,Mb=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(N)]
idle_max=10**9
dp=[[idle_max for m in range(403*400)] for i in range(N)]
used=set()
a,b,c=ABC[0]
dp[0][a*401+b]=c
for n in range(1,N):
    a,b,c=ABC[n]
    for i in range(len(dp[0])):
        if i-(a*401+b)>=0 and dp[n-1][i-(a*401+b)]!=idle_max:
            dp[n][i]=min(dp[n-1][i-(a*401+b)]+c,dp[n-1][i])
        else:
            dp[n][i]=dp[n-1][i]
    dp[n][a*401+b]=min(dp[n-1][a*401+b],c)

value=idle_max
for i in range(len(dp[0])):
    if dp[-1][i]:
        A=i//401;B=i%401
        if A and B:
            Z=gcd(A,B)
            A//=Z;B//=Z
            if Ma==A and Mb==B:
                value=min(value,dp[-1][i])
if value!=idle_max:
    print(value)
else:
    print(-1)
### BUGGY CODE ###

import collections


n = int(input())
ss = []
for i in range(n):
    s = input()
    ss.append(s)

# 以下のような数値の入力があったとする
a = ss
c = []

b = list(set(a))
for x in b:
    c.append(a.count(x))

d = dict(zip(b, c))
max_val = max(d.values())
keys_v = [i for i in d if d[i] == max_val]
keys_v.sort()
e = " ".join((map(str, keys_v)))

print(e)


### FIXED CODE ###

import bisect

n = int(input())
sl = ['']*n
for i in range(n):
    sl[i] = input()
sl = sorted(sl, key=str.lower)
# print(sl)
c = 0
anss = []
max_n = 0
for i, t in enumerate(sl):
    if i == 0:
        c += 1
        target = t
        continue

    if t == target:
        c += 1
    else:
        if max_n < c:
            anss = []
            anss.append(target)
            max_n = c
        elif max_n == c:
            anss.append(target)
            max_n = c
        target = t
        c = 1

if max_n < c:
    anss = []
    anss.append(t)
elif max_n == c:
    anss.append(t)


print(*anss)
### BUGGY CODE ###

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

a.sort()

checked = []
ans = 0
for i in range(n):
    count = 0
    if not a[i] in checked:
        for j in range(i,n):
            if a[j] == a[i]:
                count += 1
            else:
                break
        if count % 2 == 0:
            pass
        else:
            ans += 1
        checked.append(a[i])
print(ans)


### FIXED CODE ###

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

a.sort()

pre = 0
ans = 0
for i in range(n):
    count = 0
    if a[i] != pre:
        for j in range(i,n):
            if a[j] == a[i]:
                count += 1
            else:
                break
        if count % 2 == 0:
            pass
        else:
            ans += 1
        pre = a[i]
print(ans)
### BUGGY CODE ###

import sys
from heapq import *

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

ans=-1
hp=[(0,si,sj)]
dirs=[-2,-1,0,1,+2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
while hp:
    k,i,j=heappop(hp)
    if i==ti and j==tj:
        ans=k
        break
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if (abs(di)==1 and dj==0) or (di==0 and abs(dj)==1):
                nk=k
            else:
                nk=k+1
            if nk>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            heappush(hp,(nk,ni,nj))

print(ans)


### FIXED CODE ###

import sys
from heapq import *

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

ans=-1
hp=[(0,si,sj)]
dirs=[-2,-1,0,1,2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
while hp:
    k,i,j=heappop(hp)
    if i==ti and j==tj:
        ans=k
        break
    if k>dist[i][j]:
        continue
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                nk=k
            else:
                nk=k+1
            if nk>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            heappush(hp,(nk,ni,nj))

print(ans)
### BUGGY CODE ###

def resolve():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])
        if temp!=1:
            arr.append([temp, 1])
        if arr==[]:
            arr.append([n, 1])
        return arr

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    import copy

    gcddict = {}
    adiv = []
    for i in range(n):
        primes = factorization(a[i])
        adiv.append(primes)
        for j in range(len(primes)):
            if primes[j][0] in gcddict:
                gcddict[primes[j][0]] = max(gcddict[primes[j][0]], primes[j][1])
            else:
                gcddict[primes[j][0]] = primes[j][1]
    ans = 0
    for i in range(n):
        val = 1
        test = copy.deepcopy(gcddict)
        primes = adiv[i]
        for j in range(len(primes)):
            test[primes[j][0]] -= primes[j][1]
        for k in test.keys():
            val *= pow(k, test[k], mod)
        ans += val
    print(ans % mod)
resolve()

### FIXED CODE ###

def resolve():
    def lcm(X, Y):
        x = X
        y = Y
        if y > x:
            x, y = y, x
        while x % y != 0:
            x, y = y, x % y
        return X * Y // y
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = lcm(lsd, a[i])
    lsd = lsd % mod

    ans = 0
    for i in range(n):
        ans += (lsd * pow(a[i], mod-2, mod)) % mod

    print(int(ans % mod))

resolve()
### BUGGY CODE ###

import bisect

# 別解 :
N = int(input())
L = list(map(int, input().split()))

L.sort()
cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
        cnt += idx - (j + 1)

print(cnt)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))


L.sort(reverse=True)
dic = {}
cnt = 0

for i in range(1, N - 1):
    p = L[i]
    for j in range(i + 1, N):
        s = p + L[j]

        if s not in dic:
            dic[s] = 1
        else:
            dic[s] += 1

for i in range(N - 2):
    p = L[i]

    if i > 0:
        for x in range(i + 1, N):
            dic[p + L[x]] -= 1

    for key, value in dic.items():
        if key > p:
            cnt += value

print(cnt)
### BUGGY CODE ###

n, m = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a
def lcm(a,b):
	return a * b // gcd(a,b)

def p2(x):
    ans = 0
    while x % 2 == 0:
        ans += 1
        x //= 2
    return ans

n = len(a_list)

p2_list = [p2(i) for i in a_list]

p2_set = set(p2_list)
if len(p2_set) != 1:
    print(0)
else:
    p = 1
    for i in a_list:
        p = lcm(p, i//2)

    if p > m:
        print(0)
    else:
        m -= p
        print(m//(p*2)+1)

### FIXED CODE ###

n, m = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a
def lcm(a,b):
	return a * b // gcd(a,b)

def p2(x):
    ans = 0
    while x % 2 == 0:
        ans += 1
        x //= 2
    return ans

n = len(a_list)

p2_list = [p2(i) for i in a_list]

p2_set = set(p2_list)
if len(p2_set) != 1:
    print(0)
else:
    p = 1
    for i in a_list:
        p = lcm(p, i//2)
        if p > m:
            print(0)
            break
    if p <= m:
        m -= p
        print(m//(p*2)+1)
### BUGGY CODE ###

N, K = input().split(' ')
N0 = int(N)
K = int(K)
N1 = abs(N0-K)
while N1 < N0:
  N0 = N1
  N1 = abs(N1-K)
else:
  print(N0)

### FIXED CODE ###

N, K = input().split(' ')
NA = int(N)
K = int(K)
if NA - K > K:
  NA = NA - K*(NA//K - 1)
N1 = abs(NA-K)

while N1 < NA:
  NA = N1
  N1 = abs(N1-K)
else:
  print(NA)
### BUGGY CODE ###

import sys
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, 0, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = set()
h = []
for t, op, x in EVENT:
    if not op:
        STOP.remove(x)
    elif op & 1:
        STOP.add(x)
        heappush(h, x)
    else:
        while h and h[0] not in STOP:
            heappop(h)
        ans[x] = h[0] if h else -1


'''
    if op == 2:
        while h and h[0] not in STOP:
            heappop(h)
        ans[x] = h[0] if h else -1
    elif op == 1:
        STOP.add(x)
        heappush(h, x)
    elif op == 0:
        STOP.remove(x)
'''


print("\n".join(map(str, ans)))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15
from itertools import accumulate

def equal_l(cumsum,i):
    f = lambda j:abs(cumsum[i + 1] - 2*cumsum[j])
    l = 1
    r = i + 1
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) - f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_l:{0},{1}'.format(l,r))
    return cumsum[i + 1] - cumsum[l],cumsum[l]

def equal_r(cumsum,i,N):
    f = lambda j:abs(cumsum[-1] - cumsum[i + 1] - 2*(cumsum[j] - cumsum[i + 1]))
    l = i + 2
    r = N
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) -  f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_r:{0},{1}'.format(l,r))
    return  cumsum[-1] - cumsum[l],cumsum[l] - cumsum[i + 1]

def main():
    N = int(input())
    A = list(map(int,input().split()))
    cumsum = list(accumulate([0] + A))
    ans = INF
    for i in range(1,N - 2):
        a,b = equal_l(cumsum,i)
        c,d = equal_r(cumsum,i,N)
        ret = max(a,b,c,d) - min(a,b,c,d)
        ans = min(ans,ret)
    print(ans)
    
if __name__ == '__main__':
    main()
    


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15
from itertools import accumulate

def equal_l(cumsum,i):
    f = lambda j:abs(cumsum[i + 1] - 2*cumsum[j])
    l = 1
    r = i + 1
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) - f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_l:{0},{1}'.format(l,r))
    return cumsum[i + 1] - cumsum[l],cumsum[l]

def equal_r(cumsum,i,N):
    f = lambda j:abs(cumsum[-1] - cumsum[i + 1] - 2*(cumsum[j] - cumsum[i + 1]))
    l = i + 2
    r = N
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) -  f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_r:{0},{1}'.format(l,r))
    return  cumsum[-1] - cumsum[l],cumsum[l] - cumsum[i + 1]

def main():
    N = int(input())
    A = list(map(int,input().split()))
    cumsum = list(accumulate([0] + A))
    ans = INF
    for i in range(1,N - 2):
        a,b = equal_l(cumsum,i)
        c,d = equal_r(cumsum,i,N)
        ret = max(a,b,c,d) - min(a,b,c,d)
        ans = min(ans,ret)
    print(ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from math import gcd
import numpy as np

def setwise_coprime_check_fun(A_list):
    gcd_all = A_list[0]
    for i in range(N - 1):
        gcd_all = gcd(gcd_all, A_list[i + 1])
        if gcd_all == 1:
            break
    return gcd_all

def preprocess_fun(A_max):
    p_flg = [1] * (A_max + 1)
    D = [0] * (A_max + 1)
    p_flg[0] = 0
    p_flg[1] = 0
    for i in range(2, A_max + 1, 1):
        if p_flg[i]:
            for j in range(i, A_max + 1, i):
                p_flg[j] = 0
                D[j] = i
    return D

def pairwise_coprime_check(A_list, D):
    p_count = [0] * (max(A_list) + 1)
    p_count_temp = [0] * (max(A_list) + 1)
    for A in A_list:
        temp = A
        while temp != 1:
            if p_count[D[temp]] == 1:
                return 0
            else:
                p_count_temp[D[temp]] = 1
            temp = temp // D[temp]
        p_count = list(np.array(p_count) + np.array(p_count_temp))
        p_count_temp = [0] * (max(A_list) + 1)
    return 1

# 標準入力
N = int(input())
A_list = list(map(int, input().split(" ")))

# 整数の最大値を取得
A_max = max(A_list)

# 本体
if(setwise_coprime_check_fun(A_list) != 1):
    print("not coprime")
else:
    D = preprocess_fun(A_max)
    if pairwise_coprime_check(A_list, D) == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")

### FIXED CODE ###

from math import gcd
import numpy as np

def setwise_coprime_check_fun(A_list, N):
    gcd_all = A_list[0]
    for i in range(N - 1):
        gcd_all = gcd(gcd_all, A_list[i + 1])
        if gcd_all == 1:
            break
    return gcd_all

def preprocess_fun(A_max):
    p_flg = [True] * (A_max + 1)
    D = [0] * (A_max + 1)
    p_flg[0] = False
    p_flg[1] = False
    for i in range(2, A_max + 1, 1):
        if p_flg[i]:
            for j in range(i, A_max + 1, i):
                p_flg[j] = False
                D[j] = i
    return D

def pairwise_coprime_check(A_list, D):
    p_count = [0] * (max(A_list) + 1)
    for A in A_list:
        temp = A
        d = 0
        while temp != 1:
            if p_count[D[temp]] == 1 and d != D[temp]:
                return 0
            p_count[D[temp]] = 1
            d = D[temp]
            temp = temp // D[temp]
    return 1

## 標準入力
N = int(input())
A_list = list(map(int, input().split(" ")))

# 整数の最大値を取得
A_max = max(A_list)

# 本体
if(setwise_coprime_check_fun(A_list, N) != 1):
    print("not coprime")
else:
    D = preprocess_fun(A_max)
    if pairwise_coprime_check(A_list, D) == 1:
        print("pairwise coprime")
    else:
        print("setwise coprime")
### BUGGY CODE ###

import itertools

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

ans = 0
for i, j in itertools.combinations(a,2):
    ans = (ans + i*j)%(1e9+7)


print(int(ans))

### FIXED CODE ###

mod = 1000000007
n = int(input())
a = list(map(int, input().split()))
ans = 0
a_sum = sum(a) 
a_total = a_sum*a_sum
lat = 0
for i in a:
    lat = lat + i*i
ans = (a_total - lat) // 2
ans = ans%mod
print(ans)
### BUGGY CODE ###

inp = int(input())
lis = list(map(int, input().split()))

dic = {}

#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

dic_sum = dic.copy()
#calcurate
for d in dic:
  dic_sum[d]=int(dic[d]*(dic[d]-1)/2)
  
for l in lis:
  dic_sum_n = dic_sum.copy()
  if l in dic:
    dic_sum_n[l] = int(((dic[l]-1)*(dic[l]-2))/2)
    print(sum(dic_sum_n.values()))

### FIXED CODE ###

inp = int(input())
lis = list(map(int, input().split()))

dic = {}

#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

#dic_sum = dic.copy()
s = 0
#calcurate
for d in dic:
  s += int(dic[d]*(dic[d]-1)//2)
  
for i in range(inp):
  #dic_sum_n = dic_sum.copy()
  t = dic[lis[i]]
  print(s-int(t*(t-1)//2)+int((t-1)*(t-2)//2))
### BUGGY CODE ###

import math
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
for i in range(M):
    Price_List[Price_List.index(max(Price_List))] = Price_List[Price_List.index(max(Price_List))]/2
print(sum(map(lambda x:math.floor(x),Price_List)))

### FIXED CODE ###

import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))
### BUGGY CODE ###


lis = []

N,M = [int(i) for i in input().split()]
M_ = M
i = 2

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_
ret = 1
for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
            if  ret >= N:
                break
    if ret >= N and ret <=ans:
        ans = ret

print(M_//ans)


### FIXED CODE ###

import  math
lis = []

N,M = [int(i) for i in input().split()]

for i in range(1,int(math.sqrt(M))):
    if M % i == 0:
        lis.append(i)
        lis.append(M//i)


lis.sort()
i =1
for i in lis:
    if i >= N:
        break

print(M//i )
### BUGGY CODE ###

N=int(input())

k=1
for i in range(1,N+1):
    k=k*i
print(k%(10**9+7))

### FIXED CODE ###

import math

N=int(input())

k=math.factorial(N)
print(k%(10**9+7))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    S = input()

    c = [False]*1000
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                c[int(S[i])*100+int(S[j])*10+int(S[k])] = True
    print(c.count(True))

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        j = 0
        flg0 = False
        flg1 = False
        flg2 = False
        for j in S:
            if not flg0 and j==s[0]:
                flg0 = True
            elif flg0 and not flg1 and j==s[1]:
                flg1 = True
            elif flg0 and flg1 and not flg2 and j==s[2]:
                flg2 = True
        if flg0 and flg1 and flg2:
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

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


for i in range(n):
    count = 0
    before = 0
    for j, num in enumerate(a):
        if i == j:
            continue
        count += abs(before - num)
        before = num
    print(count + abs(before))
    
        

### FIXED CODE ###

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

lst = []
before = 0
for num in a:
    lst.append(abs(num - before))
    before = num
total = sum(lst)
for i in range(n):
    if i == 0:
        print(total - lst[i] - lst[i + 1] + abs(a[i+1]))
    else:
        print(total - lst[i] - lst[i + 1] + abs(a[i - 1] - a[i + 1]))