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

n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
    l, r = map(int,input().split())
    str = s[l - 1: r]
    counter = 0
    for n in range(len(str) - 1):
        if str[n] + str[n + 1] == "AC":
            counter += 1
    ans.append(counter)
for i in ans:
    print(i)

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

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

aa=[]

for i in range(n):
    aa.append(a[i]-1)
    aa.append(a[i])
    aa.append(a[i]+1)

ans=0
for i in range(min(aa),max(aa)+1):
    if ans < aa.count(i):
        ans = aa.count(i)
print(ans)

### FIXED CODE ###

import collections

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

aa=[]

for i in range(n):
    aa.append(a[i]-1)
    aa.append(a[i])
    aa.append(a[i]+1)
ans_list=collections.Counter(aa)
print(ans_list.most_common()[0][1])
### BUGGY CODE ###

def dfs(s,com):
    if s==0:
        for i in xrange(len(com)-1):
            if com[i]<com[i+1]:return
        ans.append(com)
    for i in xrange(s,0,-1):
        if s>=i:
            com+=str(i)
            dfs(s-i,com)
            com=com[0:len(com)-1]
    return ans

while 1:
    n=int(raw_input())
    if n==0:break
    ans=[]
    ans=dfs(n,"")
    for i in xrange(len(ans)):
        print(' '.join(ans[i]))

### FIXED CODE ###

def dfs(s,com):
    if s==0:
        ans.append(" ".join(map(str,com)))
        return
    for i in xrange(s,0,-1):
        if len(com)>0 and com[-1]<i:continue
        com.append(i)
        dfs(s-i,com)
        del com[-1]
    return ans

while 1:
    n=int(raw_input())
    if n==0:break
    ans=[]
    com=[]
    ans=dfs(n,com)
    for i in xrange(len(ans)):
        print(ans[i])
### BUGGY CODE ###

def game(n, m, x_list):
  if n >= m:
    return 0
  
  x_list.sort()
  interval = []
  for i in range(m - 1):
    interval.append(x_list[i + 1] - x_list[i])
    interval.sort(reverse = True)
    if len(interval) > n - 1:
      del(interval[n - 1])
  
  return abs(x_list[m - 1] - x_list[0]) - sum(interval)

n, m = map(int, input().split())
x = list(map(int, input().split()))

print(game(n, m, x))

### FIXED CODE ###

def game(n, m, x_list):
  if n >= m:
    return 0
  
  x_list.sort()
  interval = []
  for i in range(m - 1):
    interval.append(x_list[i + 1] - x_list[i])
  interval.sort(reverse = True)
  sum_interval = 0
  for i in range(n - 1):
    sum_interval += interval[i]
  return x_list[m - 1] - x_list[0] - sum_interval

n, m = map(int, input().split())
x = list(map(int, input().split()))

print(game(n, m, x))
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
for i in range(1,n):
    print(a.count(i))
print(0)

### FIXED CODE ###

import collections
n=int(input())
a=list(map(int, input().split()))
c=collections.Counter(a)
for i in range(1,n+1):
    print(c[i])
### BUGGY CODE ###

N, M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
for m in range(M):
  B, C = map(int, input().split())
  count = 0
  for i in range(B):
    if As[0] < C:
      count += 1
      As.pop(0)
  #print(As)
  index = N-count
  for i in range(N-count):
    if As[i] > C:
      index = i
      break
  As[index:index] = [C]*count
  #print(As)
print(sum(As))


### FIXED CODE ###

N, M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = []
for m in range(M):
  B, C = map(int, input().split())
  BCs.append((B, C))
BCs.sort(key=lambda BC: -BC[1])
#print(BCs)

index = 0
for m in range(M):
  B, C = BCs[m]
  for i in range(B):
    if index >= N:
      break
    if As[index] < C:
      As[index] = C
      index += 1
    else:
      break
print(sum(As))
### BUGGY CODE ###

import collections
def LI(): return list(map(int,input().split()))
N,Q = LI()
ab = [LI() for _ in range(N-1)]
px = [LI() for _ in range(Q)]
ans = [0]*(N+1) #1_index
graph = [collections.deque() for _ in range(N+1)] #1_index
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [-1]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]!=-1:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


### FIXED CODE ###

import collections,copy,sys
def LI(): return list(map(int,sys.stdin.readline().split()))
N,Q = LI()
ans = [0]*(N+1)
graph = [collections.deque() for _ in range(N+1)] #1_index
for _ in range(N-1):
    a,b = LI()
    graph[a].append(b)
    graph[b].append(a)
for _ in range(Q):
    p,x = LI()
    ans[p] += x
seen = [-1]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]!=-1:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])
### BUGGY CODE ###

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

xy = [0]*(N-1)
idx = 0

for i in range(N-1):
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy[idx] = [x,y]

        A[0] = x-y

    else:
        x = A.pop()
        y = A.pop(0)

        xy[idx] = [x,y]

        A.append(x-y)
    
    idx += 1

print(A[0])
for x, y in xy:
    print(x,y)

### FIXED CODE ###

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)
### BUGGY CODE ###

AC = 'AC'
qlist = []
N, Q = map(int, input().split())
S =  input()

for i in range(Q):
    s, e = map(int, input().split())
    qlist.append([s-1, e])

for i in qlist:
    tmp = S[i[0]:i[1]]
    print(tmp.count(AC))

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)
 
for i in range(N):
  if S[i:i+2] == 'AC':
    ac_list[i+1] = ac_list[i] + 1
  else:
    ac_list[i+1] = ac_list[i]
 
 
for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[i][0]-1])
### BUGGY CODE ###

import sys
from collections import deque

input = sys.stdin.readline
H, W = map(int, input().split())

grid = []
for _ in range(H):
    grid.append(list(input().strip()))

q = deque()
# x, y, count, pre color
q.append((0, 0, 1 if grid[0][0] == "#" else 0, grid[0][0]))

visited = [[-1 for _ in range(W)] for _ in range(H)]
ans = float("inf")
while q:
    x, y, count, pre = q.popleft()
    # print(x, y, count, pre)
    if visited[y][x] != -1 and visited[y][x] < count:
        continue
    visited[y][x] = count

    for dx, dy in ((1, 0), (0, 1)):
        nx = x + dx
        ny = y + dy
        nc = count
        if nx < 0 or W <= nx or ny < 0 or H <= ny:
            continue
        if grid[ny][nx] != pre and grid[ny][nx] == "#":
            nc += 1
        if nx == W-1 and ny == H-1:
            ans = min(ans, nc)
        else:
            q.append((nx, ny, nc, grid[ny][nx]))

# print(visited)
print(ans)  

### FIXED CODE ###

import sys
from collections import deque

input = sys.stdin.readline
H, W = map(int, input().split())

grid = []
for _ in range(H):
    grid.append(list(input().strip()))

q = deque()
# x, y, count, pre color
q.append((0, 0, 1 if grid[0][0] == "#" else 0, grid[0][0]))

visited = [[-1 for _ in range(W)] for _ in range(H)]
ans = float("inf")
while q:
    x, y, count, pre = q.popleft()
    # print(x, y, count, pre)
    v_score = visited[y][x]
    if v_score != -1 and v_score <= count:
        continue
    visited[y][x] = count

    for dx, dy in ((1, 0), (0, 1)):
        nx = x + dx
        ny = y + dy
        nc = count
        if nx < 0 or W <= nx or ny < 0 or H <= ny:
            continue
        n_color = grid[ny][nx]
        if n_color != pre and n_color == "#":
            nc += 1
        if nx == W-1 and ny == H-1:
            ans = min(ans, nc)
            print(ans)
            sys.exit()
        else:
            if visited[ny][nx] != -1 and visited[ny][nx] <= nc:
                continue
            if count == nc:
                q.appendleft((nx, ny, nc, n_color))
            else:
                q.append((nx, ny, nc, n_color))

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

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

hantei = 10 ** 18
kekka = 1
for x in range(n):
    kekka = kekka * m[x]

if kekka > hantei:
    print("-1")
else:
    print(kekka)

### FIXED CODE ###

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

hantei = 10 ** 18
kekka = 1
m.sort()
for x in range(n):
    kekka = kekka * m[x]
    if kekka > hantei:
        print("-1")
        exit()

print(kekka)
### BUGGY CODE ###

N,C=map(int, input().split())
#Aは時計回り
A,B=[],[]
allv=0
for i in range(N):
  a,b=map(int, input().split())
  A.append([a,b])
  B.append([C-a,b])
  allv+=b
A,B=sorted(A),sorted(B)
OA,OB,AS,BS=[],[],[],[]
ax,av,bx,bv=0,0,0,0
for i in range(N):
  ax,bx=A[i][0],B[i][0]
  av+=A[i][1]
  bv+=B[i][1]
  OA.append((ax,av))
  OB.append((bx,bv))
  AS.append(av-ax)
  BS.append(bv-bx)
#OA→AO→OBといくとき
ansa=0
for i in range(N-1):
  #iまで行く
  bma=N-i
  oa=OA[i][1]-OA[i][0]
  ao=-OA[i][0]
  ob=max(BS[:N-i-1])
  d=max(oa,oa+ao+ob)
  ansa=max(ansa,d)
ansb=0
for i in range(N-1):
  #iまで行く
  ama=N-i
  ob=OB[i][1]-OB[i][0]
  bo=-OB[i][0]
  oa=max(AS[:N-i-1])
  d=max(ob,ob+bo+oa)
  ansb=max(ansb,d)
print(max(ansa,ansb,allv-(C-max(OA[0][0],OB[0][0]))))

### FIXED CODE ###

N,C=map(int, input().split())
#Aは時計回り
A,B=[],[]
allv=0
for i in range(N):
  a,b=map(int, input().split())
  A.append([a,b])
  B.append([C-a,b])
  allv+=b
A,B=sorted(A),sorted(B)
OA,OB,AS,BS=[],[],[],[]
ax,av,bx,bv=0,0,0,0
for i in range(N):
  ax,bx=A[i][0],B[i][0]
  av+=A[i][1]
  bv+=B[i][1]
  OA.append((ax,av))
  OB.append((bx,bv))
  AS.append(av-ax)
  BS.append(bv-bx)
#OA→AO→OBといくとき
d=BS[0]
e=AS[0]
BSma,ASma=[-10000]*N,[-10000]*N
for i in range(N):
  BSma[i]=max(d,BS[i])
  d=BSma[i]
  ASma[i]=max(e,AS[i])
  e=ASma[i]
  
ansa=0
for i in range(N-1):
  #iまで行く
  bma=N-i
  oa=OA[i][1]-OA[i][0]
  ao=-OA[i][0]
  ob=BSma[-2-i]
  d=max(oa,oa+ao+ob)
  ansa=max(ansa,d)
ansb=0
for i in range(N-1):
  #iまで行く
  ama=N-i
  ob=OB[i][1]-OB[i][0]
  bo=-OB[i][0]
  oa=ASma[-2-i]
  d=max(ob,ob+bo+oa)
  ansb=max(ansb,d)
print(max(ansa,ansb,allv-(C-max(OA[0][0],OB[0][0]))))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
s = input()

# search A
listA = []
for i in range(len(s) - 1, -1, -1):
    if s[i] == "A":
        listA.append(i)

cnt = 0
for a in listA:
    while s[a : a + 3] == "ABC":
        s = s[: a] + "BCA" + s[a + 3 :]
        a += 2
        cnt += 1

print(cnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()

s = s.replace("BC", "*")

point = 0
charge = 0
for i in range(len(s) - 1, -1, -1):
    if s[i] == "*":
        charge += 1
    elif s[i] == "A":
        point += charge
    else:
        charge = 0

print(point)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    N=int(input())
    l,r=0,N
    print(0)
    s=input()
    ls=s
    if s!='Vacant':
        while True:
            x=(l+r)//2
            print(x)
            s=input()
            if s=='Vacant':break
            elif ((x-l)%2==0 and s==ls) or ((x-l)%2==1 and s!=ls):
                l=x
                ls=s
            else:
                r=x



if __name__=='__main__':
    main()

### FIXED CODE ###

N=int(input())
l,r=0,N
print(0)
s=input()
ls=s
if s!='Vacant':
    for i in range(19):
        x=l+(r-l)//2
        print(x)
        s=input()
        if s=='Vacant':
            break
        elif (x-l)%2==0 and s==ls or (x-l)%2==1 and s!=ls:
            l=x
            ls=s
        else:
            r=x
### BUGGY CODE ###

d, n = map(int,input().split())

result = 0
for i in range(1,n+1):
  if (i*100**d) // (100**d) // 100 == 0:
    result = i*100**d
  else:
    j = 0
    while not(((i+j)*100**d) // (100**d) //100 == 0):
      j += 1
      result = (i+j)*(100**d)

print(result)


### FIXED CODE ###

d, n = map(int,input().split())

result = 0
for i in range(1,n+1):
  if i // 100 == 0:
    result = i*(100**d)
  else:  
    j = 1
    result = (i+j)*(100**d)

print(result)
### BUGGY CODE ###

H,W=map(int,input().split())
white=0
S=[]
for _ in range(H):
    s=list(input())
    white+=s.count('.')
    S.append(s)

f=[[0 for i in range(W)] for j in range(H)]

def path(i,j):
    s=S[i][j]
    q=[]
    for k in [1,-1]:
        if 0<=i+k<H and f[i+k][j]==0 and S[i+k][j]==s:
            q.append((i+k,j))
        if 0<=j+k<W and f[i][j+k]==0 and S[i][j+k]==s:
            q.append((i,j+k))
    return q

flag=False
if S[0][0]=='.' and S[-1][-1]=='.':
    que = path(0,0)
else:
    que = []
f[0][0]=1

l=1
while len(que)>0 and flag==False:
    l+=1
    tmp=[]
    for q in que:
        tmp+=path(*q)
        f[q[0]][q[1]]=1
        if q==(H-1,W-1):
            flag=True
    que=tmp

if flag:
    print(white-l)
else:
    print(-1)


### FIXED CODE ###

H,W=map(int,input().split())
white=0
S=[]
for _ in range(H):
    s=list(input())
    white+=s.count('.')
    S.append(s)

f=[[0 for i in range(W)] for j in range(H)]

def path(i,j):
    q=[]
    for k in [1,-1]:
        if 0<=i+k<H and f[i+k][j]==0 and S[i+k][j]=='.':
            q.append((i+k,j))
        if 0<=j+k<W and f[i][j+k]==0 and S[i][j+k]=='.':
            q.append((i,j+k))
    return q

flag=False
if S[0][0]=='.' and S[-1][-1]=='.':
    que = path(0,0)
else:
    que = []
f[0][0]=1

l=1
while len(que)>0 and flag==False:
    l+=1
    tmp=[]
    for q in que:
        if f[q[0]][q[1]]==0:
            tmp+=path(*q)
            f[q[0]][q[1]]=1
            if q==(H-1,W-1):
                flag=True
        que=tmp

if flag:
    print(white-l)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
 
answer = 0
mod = 1000000007
for i in range(N-1):
  total = sum(A[i+1:])
  multi = A[i] * total
  answer += multi
print(str(answer % mod))

### FIXED CODE ###

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

answer = 0
a_sum = sum(A)
mod = 10**9+7

for i in range(N-1):
  a_sum -= A[i]
  answer += a_sum * A[i]
print(str(answer % mod))
### BUGGY CODE ###

*s, = input()
_q = int(input())
for _ in range(_q):
    *q, = map(str, input().split())
    q.extend([" ", " "])
    t = q[0]
    f = q[1]
    c = q[2]

    if t == "1":
        *s, = reversed(s)
    else:
        if f == "1":
            s.insert(0, c)
        else:
            s.append(c)

print("".join(s))


### FIXED CODE ###

*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

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

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

ans = 0
for i, s in enumerate(S):
    if i == N-1:
        break
    if s is '#':
        ans__ = 0
        flag = -1
        count = i
        for s_ in S[count+1:]:
            if count + 1 == N or s_ is '#':
                break
            if s_ is '.' :
                flag = 1
                ans__ += 1
        if flag == 1:
            ans_ = 1
            c = i
            while c >= 1:
                if S[c-1] is '#':
                    ans_ += 1
                c -= 1
            ans += min(ans_, ans__)

print(ans)


### FIXED CODE ###

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

white_all = S.count('.')
ans = white_all

white = 0
black = 0
for i, s in enumerate(S):
    if s is '.':
        white += 1
    else:
        black += 1
    ans = min(black+(white_all-white), ans)

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

import sys
from bisect import bisect
from itertools import accumulate

n, t = map(int, input().split())
constant = []
variable = []
for line in sys.stdin:
    a, b = map(int, line.split())
    if a == 0:
        constant.append(b + 1)
    else:
        variable.append((a / (b + 1), a, b))
constant.sort()
variable.sort(reverse=True)
INF = 10 ** 10
t += 1
t2 = t.bit_length() + 1
# dp[j]: (i番目まで見て) j件の店で買い物を完了した時の、次の店に到着できる最短時間
dp = [INF] * t2
dp[0] = 1
for _, a, b in variable:
    for j in range(t2 - 1, -1, -1):
        if dp[j] == INF:
            continue
        tmp = (a + 1) * dp[j] + b + 1
        if tmp > t:
            continue
        if dp[j + 1] > tmp:
            dp[j + 1] = tmp

const_acc = list(accumulate(constant))
ans = 0

for i, c in enumerate(dp):
    if c == INF:
        break
    remaining = t - c
    k = bisect(const_acc, remaining)
    ans = max(ans, i + k)

print(ans)


### FIXED CODE ###

import sys
from bisect import bisect
from itertools import accumulate

n, t = map(int, input().split())
constant = []
variable = []
for line in sys.stdin:
    a, b = map(int, line.split())
    if a == 0:
        constant.append(b + 1)
    else:
        variable.append((a / (b + 1), a, b))
constant.sort()
variable.sort(reverse=True)
INF = 10 ** 10
t += 1
t2 = t.bit_length() + 1
# dp[j]: (i番目まで見て) j件の店で買い物を完了した時の、次の店に到着できる最短時間
dp = [INF] * t2
dp[0] = 1
for _, a, b in variable:
    for j in range(t2 - 1, -1, -1):
        if dp[j] == INF:
            continue
        tmp = (a + 1) * dp[j] + b + 1
        if tmp > t:
            continue
        if dp[j + 1] > tmp:
            dp[j + 1] = tmp

const_acc = list(accumulate(constant))
ans = 0

for i, c in enumerate(dp):
    if c == INF:
        break
    remaining = t - c
    k = bisect(const_acc, remaining)
    ans = max(ans, i + k)

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

def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x%2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i not in divisor_lst and x%i==0:
                    return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    divisor_lst = []
    while True:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])
        if i>j:
            break

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

### FIXED CODE ###

n = int(input())

need_lst = []
for i in range(1,int(n**(1/2)+1)):
    if n%i==0:
        need = i+n//i
        need_lst.append(need-2)

print(min(need_lst))
### BUGGY CODE ###

n = int(input())
s = list(map(int, list(input())))
ans = 0
for i in range(1000):
    pin = [i // 100, i // 10 % 10, i % 10]
    idx = 0
    for c in s:
        if c == pin[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break
print(ans)

### FIXED CODE ###

# 000~999で決め打ちして数える
# TLEになるんだけどこれそんなに重いか？？？？？

n = int(input())
s = input()
ans = 0

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

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

import numpy as np
import copy
#import time

N = int(raw_input().replace("\n", ""))

a_array = np.asarray(sorted([int(raw_input().replace("\n", "")) for i in xrange(N)]))
len_array = a_array.shape[0]

if len_array % 2 == 0:
    elm_is = [len_array/2 -1, len_array/2]
else:
    elm_is = [(len_array-1)/2]
aa_array = a_array[elm_is]

#s_time = time.time()


sum_diffs = []
#for elm_i, start_elm in enumerate(a_array):
for elm_i, start_elm in zip(elm_is, aa_array):
    mask = np.ones(len_array, dtype=bool)
    target_elm = start_elm

    sum_diff = 0
    for count in xrange(len_array - 1):
        #c_time = time.time()
        mask[elm_i] = False
        masked_a_array = a_array[mask]
        relative_a_array = np.abs(masked_a_array - target_elm)
        target_elm_index = np.argmax(relative_a_array)
        target_elm = masked_a_array[target_elm_index]
        sum_diff += relative_a_array[target_elm_index]
        
        #print("mae:", time.time() - c_time)
        #c_time = time.time()
        count_ = -1
        for mask_i, elm in enumerate(mask):
            if elm:
                count_ += 1
                if count_ == target_elm_index:
                    elm_i = mask_i
                    break
        #print("ato:", time.time() - c_time)
    
    sum_diffs.append(sum_diff)

print max(sum_diffs)
#print(time.time() - s_time)

### FIXED CODE ###

import numpy as np
import copy

N = int(raw_input().replace("\n", ""))

a_array = np.asarray(sorted([int(raw_input().replace("\n", "")) for i in xrange(N)]))

len_array = len(a_array)

coffs = np.ones(len(a_array), dtype=bool) * 2

if len_array % 2 == 0:
    coffs = [-2] * ((len_array - 1) / 2) + [-1] + [1] + [2] * ((len_array -1) / 2)
    out = np.dot(a_array, coffs)
else:
    coffs1 = [-2] * ((len_array-3) / 2) + [-1] * 2 + [2] * ((len_array-1) / 2)
    coffs2 = [-2] * ((len_array-1) / 2) + [1] * 2 + [2] * ((len_array-3) / 2)
    out1 = np.dot(a_array, coffs1)
    out2 = np.dot(a_array, coffs2)
    out = max(out1, out2)

print out
### BUGGY CODE ###

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

odds = list(map(lambda x: 0.5*(x-1)+1,dice))

max_n = 0
for i in range(n-k+1):
    sum_odds = sum(odds[i:k+i])
    if sum_odds > max_n:
        max_n = sum_odds


        
print(max_n)

### FIXED CODE ###

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

dice_cumsum = [0]*(n+1)

for i in range(1,n+1):
    dice_cumsum[i] = dice_cumsum[i-1] + dice[i-1]
    
max_n = 0
max_i = 0
for i in range(n-k+1):
    sum_dice = dice_cumsum[k+i] - dice_cumsum[i]
    if sum_dice > max_n:
        max_n = sum_dice
        max_i = i

sum_odds = 0
for i in range(k):
    sum_odds += (dice[max_i+i]-1)*0.5+1

print(sum_odds)
### BUGGY CODE ###

import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,x = li()
a = list(li())

# 係数リスト
coef = [5] + [2*i + 5 for i in range(n+1)]

a = a[::-1]
a_cum = [0] + list(accumulate(a))

ans = float("inf")
# 往復回数決め打ち
for k in range(1,n+1):
    cost = (n+k) * x
    i = 0
    while i*k <= n:
        cost += coef[i]*(a_cum[min((i+1)*k, n)] - a_cum[i*k])
        i += 1

    ans = min(ans, cost)
    
print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,x = li()
a = list(li())

# 係数リスト
coef = [5] + [2*i + 5 for i in range(n+1)]

a = a[::-1]
a_cum = [0] + list(accumulate(a))

ans = float("inf")
# 往復回数決め打ち
for k in range(1,n+1):
    cost = (n+k) * x
    i = 0
    while i*k <= n:
        cost += coef[i]*(a_cum[min((i+1)*k, n)] - a_cum[i*k])
        i += 1

    ans = min(ans, cost)
    
print(ans)