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

N = int(input())
S = input()

A = []

for n in range(N):
    if n == 0:
        L = 0
        R = sum([s != 'W' for s in S[n+1:]])
    elif n == N-1:
        L = sum([s != 'E' for s in S[:n]])
        R = 0
    else:
        L = sum([s != 'E' for s in S[:n]])
        R = sum([s != 'W' for s in S[n+1:]])
    A.append(L+R)

print(min(A))


### FIXED CODE ###

N = int(input())
S = input()

A = []

for n in range(N):
    if n == 0:
        L = 0
        R = sum([s == 'E' for s in S[n+1:]])
    else:
        L += 0 if S[n-1] == 'E' else 1
        R -= 0 if S[n]   != 'E' else 1
    A.append(L+R)

print(min(A))
### BUGGY CODE ###

import heapq
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = [list(map(int, input().split())) for i in range(M)]

    A.sort()
    BC.sort(key=lambda x: x[1], reverse=True)
    BC2 = []

    for bc in BC:
        for i in range(bc[0]):
            BC2.append(bc[1])
    
    BC_idx = 0
    for i in range(N):
        if BC_idx >= len(BC2):
            break
        if A[i] < BC2[BC_idx]:
            A[i] = BC2[BC_idx]
            BC_idx += 1

    print(sum(A))

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    N, M = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    operate = []
    for _ in range(M):
        b, c = map(int,input().split())
        operate.append([b,c])
    operate.sort(reverse=True, key=lambda x:x[1])    

    rewrite = [0] * N
    idx = 0
    for b,c in operate:
        for i in range(b):
            rewrite[idx] = c
            idx += 1
            if idx == N:
                break
        if idx == N:
            break
    
    ans = 0
    for i in range(N):
        ans += max(A[i],rewrite[i])
    
    print(ans)

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

N = int(input())
li = list(map(int,input().split()))
ans = []
for i in range(N):
  for j in range(N):
    if li[j] == i+1:
      ans.append(j+1)
for i in range(N):
  print(ans[i],end=' ')

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
li = list(map(int,input().split()))
ans = [0] * N
for i in range(N):
    ans[li[i]-1] = i+1
for j in range(N):
    print(ans[j],end = ' ')
### BUGGY CODE ###

MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0 for j in range(S+1)] for i in range(N+1)] #dp[i][j] = i番目まで見て重さjのものを取る方法
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= MOD
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD

for i in range(1, N):
    for j in range(S+1):
        non_get = 0
        get = 0
        non_get = dp[i-1][j] % MOD
    
        if j - A[i] >= 0:
            get = dp[i-1][j - A[i]] % MOD
        dp[i][j] = (2*non_get + get) % MOD
        
        

print(dp[N][S])            

# print(dp)
        

### FIXED CODE ###

MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0 for j in range(S+1)] for i in range(N+1)] #dp[i][j] = i番目まで見て重さjのものを取る方法
dp[0][0] = 1

# for i in range(N):
#     for j in range(S+1):
#         dp[i+1][j] += 2*dp[i][j]
#         dp[i+1][j] %= MOD
#         if j + A[i] <= S:
#             dp[i+1][j+A[i]] += dp[i][j]
#             dp[i+1][j+A[i]] %= MOD

for i in range(1, N+1):
    for j in range(S+1):
        get = 0
        non_get = 2*dp[i-1][j] % MOD
    
        if j - A[i-1] >= 0:
            get = dp[i-1][j - A[i-1]]
        dp[i][j] = (non_get + get) % MOD
        
        

print(dp[N][S])            

# print(dp)
### BUGGY CODE ###

class LinkedList(object):
    def __init__(self):
        self.first = None
        self.last = None

    def insert(self, key):
        if not self.first:
            self.first = self.last = {'key':key, 'next':None, 'prev':None}
        else:
            self.first = {'key':key, 'next':self.first, 'prev':None}
            self.first['next']['prev'] = self.first

    def delete(self, key):
        node = self.first
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.first['next']['prev'] = None
            self.first = self.first['next']

    def deleteLast(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.last['prev']['next'] = None
            self.last = self.last['prev']

    def show(self):
        if not self.first:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print(' '.join(res))

def run():
    n = int(input())
    linked_list = LinkedList()
    for _ in range(n):
        order = input()
        if order.startswith('insert'):
            linked_list.insert(order.split()[1])
        elif order.startswith('deleteFirst'):
            linked_list.deleteFirst()
        elif order.startswith('deleteLast'):
            linked_list.deleteLast()
        elif order.startswith('delete'):
            linked_list.delete(order.split()[1])
    linked_list.show()

if __name__ == '__main__':
    run()




### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

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

line_one = raw_input().split()
n = int(line_one[0])
k = int(line_one[1])

l = []
#d = {}
for i in range(n):
    line_one2 = raw_input().split()
    a1 = int(line_one2[0])
    b1 = int(line_one2[1])
    if a1 in l:
        #d[a1] += b1
        l[a1][1] += b1
    else:
        l.append( ( a1, b1 ))
        #//d[a1] = b1

l.sort()
count = 0
for item in l:
    count += item[1]
    if k <= count:
        print item[0]
        break


### FIXED CODE ###

line_one = raw_input().split()
n = int(line_one[0])
k = int(line_one[1])

l = []
#d = {}
for i in range(n):
    line_one2 = raw_input().split()
    a1 = int(line_one2[0])
    b1 = int(line_one2[1])
    l.append( ( a1, b1 ))
    #if a1 in l:
    #    #d[a1] += b1
    #    l[a1][1] += b1
    #else:
    #    l.append( ( a1, b1 ))
    #    #//d[a1] = b1

#l.sort()
l = sorted(l, key=lambda x: x[0])
count = 0
for item in l:
    count += item[1]
    if k <= count:
        print item[0]
        break
### BUGGY CODE ###

from numpy.linalg import solve

N = int(input())
right = list(int(x) * 2 for x in input().split())
 
left = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    left[i][i] = 1
    if i < N - 1:
        left[i][i + 1] = 1
    
left[N - 1][0] = 1

# for i in range(N):
#     num = []
#     for j in range(N):
#         if j == i or j == (i + 1):
#             num.append(1)
#         else:
#             num.append(0)
#         if i == N - 1:
#             num[0] = 1        
#     left.append(num)

#print(left)

answer = ""
for a in solve(left, right):
    answer += str(int(a))
    answer += " "

print(answer)

### FIXED CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

N = int(input())
a_ = list(int(x) for x in input().split())
X_ = [0 for _ in range(N)]

X_sum = sum(a_)
logging.info("sum = " + str(X_sum))

X_[0] = X_sum - 2 * sum(a_[1::2])
logging.info("X_1 = " + str(X_[0]))

for i in range(1, N):
    X_[i] = 2 * a_[i - 1] - X_[i - 1]

answer = ""
for i in X_:
    answer += str(i)
    answer += " "

print(answer)
### BUGGY CODE ###

N,Q=list(map(int,input().strip().split(' ')))
gr=[[] for _ in range(N)]
val=[0]*N
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    gr[a]+=[b]
    gr[b]+=[a]
for _ in range(Q):
    p,x=list(map(int,input().strip().split(' ')))
    p-=1
    val[p]+=x
ans=[0]*N
stack=[0]
checked=[0]*N
checked[0]=1
ans[0]=val[0]
while stack:
    x=stack.pop()
    for v in gr[x]:
        if checked[v]==0:
            stack+=[v]
            checked[v]=1
            ans[v]=ans[x]+val[v]
for x in ans:
    print(x,end=" ")

### FIXED CODE ###

N,Q=list(map(int,input().strip().split(' ')))
gr=[[] for _ in range(N)]
val=[0]*N
for _ in range(N-1):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    gr[a]+=[b]
    gr[b]+=[a]
for _ in range(Q):
    p,x=list(map(int,input().strip().split(' ')))
    p-=1
    val[p]+=x
ans=[0]*N
stack=[0]
checked=[0]*N
checked[0]=1
ans[0]=val[0]
while stack:
    x=stack.pop()
    for v in gr[x]:
        if checked[v]==0:
            stack+=[v]
            checked[v]=1
            ans[v]=ans[x]+val[v]
ans=[str(x) for x in ans]

print(" ".join(ans))
### BUGGY CODE ###

import numpy as np

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

dp = np.zeros((n + 1, k), bool)
dp[0][0] = True
for i, e in enumerate(a, 1):
    dp[i] = dp[i-1]
    dp[i, e:] |= dp[i-1, :-e]

dp2 = np.zeros((n + 1, k), bool)
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    dp2[i] = dp2[i-1]
    dp2[i, e:] |= dp2[i-1, :-e]

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while j > 0 and e2 + li2[j] >= k:
            j -= 1

        if e2 + li2[j] < k:
            mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


### FIXED CODE ###

import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


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

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
s=set()
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            s.add(x)
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
    else:
        B.append(x)


ans=0
for x in B:
    for j in range(1,int(x**0.5)+1):
        if j==1:
            if x==1:
                continue
            else:
                if j in s:
                    break
        elif x%j==0:
            if x//j in s or j in s:
                break
    else:
        ans+=1
    s.add(x)
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
bl=[0]*(10**6+1)
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
            xx=x
            while x<=10**6:
                bl[x]=1
                x+=xx
    else:
        B.append(x)


ans=0
for x in B:
    ans+=not bl[x]
    xx=x
    while x<=10**6:
        bl[x]=1
        x+=xx
print(ans)
### BUGGY CODE ###

X = int(input())

if X < 100:
    print(0)
    exit()


def dfs(zan):
    if zan <= 0:
        if zan == 0:
            print(1)
            exit()
        else:
            return

    dfs(zan - 100)
    dfs(zan - 101)
    dfs(zan - 102)
    dfs(zan - 103)
    dfs(zan - 104)
    dfs(zan - 105)


dfs(X)
print(0)

### FIXED CODE ###

X = int(input())

if X < 100:
    print(0)
    exit()

if X % 100 == 0:
    print(1)
    exit()

cnt = X // 100
zan = X % 100

if zan > cnt * 5:
    print(0)
else:
    print(1)
### BUGGY CODE ###

N, M = map(int, input().split())
st = set(range(1, N+1))
for _ in range(M):
    a, b = map(int, input().split())
    st.intersection_update(set(range(a, b+1)))
print(len(st))

### FIXED CODE ###

N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
Lmax = max(L)
Rmin = min(R)
if Lmax>Rmin:
    print(0)
else:
    print(Rmin-Lmax+1)
### BUGGY CODE ###

N = int(input())
X = input()
memo = {}


def popcount(x: str):
    return x.count("1")


def f(x: str):
    n = int("0b"+x, 2)
    ops = 0
    while n != 0:
        if memo.get(x) is None:
            pc = popcount(x)
            n %= pc
            memo[x] = n
        else:
            n = memo[x]
        # print(f"popcount({n}) = {pc} => n%{pc} = {n%pc}")
        ops += 1
        x = bin(n)[2:]
    return ops


def rev(x: str, i: int):
    x = list(x)
    if x[i] == "1":
        x[i] = "0"
    else:
        x[i] = "1"
    return "".join(x)


if __name__ == "__main__":
    for i in range(N):
        print(f(rev(X, i)))


### FIXED CODE ###

N = int(input())
X = input()
memo = {}
X_int = int(X, 2)


def popcount(n: int):
    x = bin(n)[2:]
    return x.count("1")


pcf = popcount(int(X, 2))
pcm = pcf - 1
pcp = pcf + 1
xm = X_int % pcm if pcm != 0 else 0
xp = X_int % pcp


def f(n: int, ops: int):

    while n != 0:
        n %= popcount(n)
        ops += 1
    return ops


def rev(x: str, i: int):
    if x == "1":
        if pcm == 0:
            return -1
        n = (xm - (pow(2, N-i-1, pcm))) % pcm
    else:
        n = (xp + (pow(2, N-i-1, pcp))) % pcp
    return n


if __name__ == "__main__":
    for i, x in enumerate(X):
        n = rev(x, i)
        if n == -1:
            print(0)
        else:
            print(f(n, 1))
### BUGGY CODE ###

n = int(input())
ab = str(input())

ans = [0]
lenab = len(ab)

for h in range(lenab):
    abc = ab[h:]
    lenabc = len(abc)
    i = 1; j = 0
    while i < lenabc:
        while i+j < lenabc and abc[j] == abc[i+j] and j < i:
            j += 1
        if j == 0:
            i += 1
        else:
            ans.append(j)
            i += 1
            j=0

print(max(ans))

### FIXED CODE ###


n = int(input())
ab = str(input())

ans = set([0])
lenab = len(ab)

for h in range(lenab):
    abc = ab[h:]
    lenabc = len(abc)
    i = 1; j = 0
    A = [0]*lenabc
    A[0] = lenabc
    while i < lenabc:
        while i+j < lenabc and abc[j] == abc[i+j] and j < i:
            j += 1
        if j == 0:
            i += 1
        else:
            A[i] = j
            ans.add(j)
            k = 1
            while lenabc - i > k < j - A[k] and j < i - k :
                A[i + k] = A[k]
                k += 1
            i += k;
            j -= k

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

import numpy as np

def getNearestValue(list, num):
    idx = np.searchsorted(list, num, side="left")
    if idx > 0 and (idx == len(list) or abs(num - list[idx-1]) < abs(num - list[idx])):
        return list[idx-1]
    else:
        return list[idx]

#    idx = np.abs(np.asarray(list) - num).argmin()
#    return list[idx]

def main():
    A, B, Q = map(int, input().split())  #複数数値入力
    S = [0] * A
    T = [0] * B
    X = [0] * Q
    for i in range(A):
        S[i] = int(input())
    for i in range(B):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    for i in range(Q):
        ans = 0

        # 1:神社先
        basyo1 = getNearestValue(S, X[i])   
        dist1 = abs(basyo1 - X[i])
        dist1 += abs(getNearestValue(T, basyo1) -basyo1)

        # 2:寺先
        basyo2 = getNearestValue(T, X[i])
        dist2 = abs(basyo2 - X[i])
        dist2 += abs(getNearestValue(S, basyo2) -basyo2)

        ans += min(dist1, dist2)
        print(ans)


main()

### FIXED CODE ###

import bisect

A, B, Q = map(int, input().split())  # 複数数値入力
S = [0] * A
T = [0] * B
X = [0] * Q
for i in range(A):
    S[i] = int(input())
for i in range(B):
    T[i] = int(input())
for i in range(Q):
    X[i] = int(input())

S.insert(0, -float("inf"))
S.append(float("inf"))
T.insert(0, -float("inf"))
T.append(float("inf"))

for i in range(Q):
    b = bisect.bisect_right(S, X[i])
    d = bisect.bisect_right(T, X[i])
    res = float("inf")
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            d1 = abs(s - X[i]) + abs(t - s)  # 先に神社
            d2 = abs(t - X[i]) + abs(t - s)  # 先に寺
            res = min(res, d1, d2)

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

N=int(input())
List=list(map(int,input().split()))
ans=0
for i in range(N):
    if min(List[:i+1])==List[i]:
        ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
ans=0
champ=10**6
for p in list(map(int,input().split())):
    if p<champ:
        ans+=1
        champ=p

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

S = input()
Q = int(input())

flip = 0
for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flip += 1
        flip %= 2
    else:
        if (int(q[1]) + flip)%2 == 0:
            S = "".join([S,q[2]])
        else:
            S = "".join([q[2],S])

if flip == 0:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

flip = 0
for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flip += 1
        flip %= 2
    else:
        if (int(q[1]) - 1 + flip)%2 == 0:
            S.appendleft(q[2])
        else:
            S.append(q[2])

S = list(S)
if flip == 0:
    print(*S, sep="")
else:
    print(*S[::-1], sep="")
### BUGGY CODE ###

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

for i in range(n):
    l = a.copy()
    l_q = []
    ttl = 0

    del l[i]
    ll = list(set(l))
    for i in ll:
        l_q.append(l.count(i))
    for i in l_q:
        if i >=2:
            ttl += i * (i - 1) / 2
    print(int(ttl))

    

### FIXED CODE ###

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

from collections import Counter

ttl = 0
cnt = Counter(a)
for i in cnt.values():
    ttl += i * (i - 1) // 2

k_ttl = 0
for i in range(n):
    print(ttl - (cnt[a[i]] - 1))
### BUGGY CODE ###

X = input()
N = len(X)

st = "ST"
con = X.count(st)

while con > 0:
  X = X.replace(st,"")
  con = X.count(st)
  
print(len(X))

### FIXED CODE ###

from collections import deque

X = input()
N = len(X)
S = "S"
T = "T"
stack = deque("")

for i,str in enumerate(X):
  if str == S:
    stack.append(str)
  elif str == T:
    if len(stack) == 0:
      stack.append(str)
    elif stack[-1] == T:
      stack.append(str)
    elif stack[-1] == S:
      stack.pop()
      
print(len(stack))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
cnt = 0
acIdx = [0]
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cnt += 1
    acIdx.append(cnt)

for i in range(q):
    l, r = map(int, input().split())
    print(acIdx[r-1] - acIdx[l-1])
### BUGGY CODE ###

n = int(input())
s = input()

max_count = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        if s[i] == s[j]:
            count = max_count + 1
            while True:
                if i+count <= j and s[i:i+count] == s[j:j+count]:
                    #print(count, i, s[i:i+count])
                    count += 1
                else:
                    max_count = max(max_count, count-1)
                    break
print(max_count)

### FIXED CODE ###

tmp = input()
my_str = input()
 
start = 0
end = 1
max_len = 0
 
while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        if end - start > max_len:
            max_len = end - start
        end += 1
    else:
        start += 1
print(max_len)
### BUGGY CODE ###

from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    LIST = []
    for i in range(40):
        LIST.append(2019*i)
    start = 0
    cnt = 0
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            #print(S[start:i])
            if int(S[start:i]) in LIST:
                cnt += 1
        start += 1
    print(cnt)
if __name__ == '__main__':
  main()


### FIXED CODE ###

S = input()
lenS = len(S)
count = [0] * 2019
count[0] = 1
num = 0
d = 1
for i in range(lenS):
    num += int(S[lenS - i - 1]) * d
    count[num%2019] += 1
    d *= 10
    d %= 2019
ans = 0
for i in count:
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
A = []
for i in range(len(p)-K+1):
    P = p[i:i+K]
    if ans < sum(P):
        ans2 = P
    ans = max(ans,sum(ans2)) 
B = (sum(ans2)+K)/2
print(B)

### FIXED CODE ###

from itertools import accumulate
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
for i in range(N):
    P[i] = 1+(P[i]-1)/2
ruiseki = list(accumulate([0]+P))
ans = 0
for i in range(N-K+1):
    ans = max(ans,ruiseki[i+K]-ruiseki[i])
print(ans)
### BUGGY CODE ###

n = int(input())
attends = [int(each) for each in input().split(' ')]
ordered = sorted(attends)
ans = ''
for each in ordered:
    ans += str(attends.index(each) + 1) + ' '
print(ans)

### FIXED CODE ###

from operator import itemgetter
n = int(input())
ordered_info = [ [i, int(num)] for i, num in zip(range(n), input().split(' '))]
ordered_info.sort(key = itemgetter(1))
ans = ''
for i, _ in ordered_info:
    print(i+1, end=' ')
### BUGGY CODE ###

input = open(0).read

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


def main():
    l = [abs(A[i + 1] - A[i]) for i in range(N - 1)]
    print(sum(l) - l[0] + abs(A[1]) + abs(A[-1]))

    if N != 2:
        print("\n".join(
            [str(abs(A[0]) + sum(l) - l[i] - l[i + 1] + abs(A[i] - A[i + 2])
                 + abs(A[-1])) for i in range(N - 2)]))

    print(abs(A[0]) + sum(l) - l[-1] + abs(A[-2]))
    return


main()


### FIXED CODE ###

def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    l = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    num = sum(l)
    print("\n".join(
        [str(num - l[i] - l[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()