Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(10**9)

H, W, K = list(map(int, input().split()))
S = [''] * H
for i in range(H):
    S[i] = input()
ans = H * W

for bit in range(2**(H-1)):
    cnt = bin(bit).count('1')
    id = [0] * H
    for i in range(H-1):
        if bit>>i & 1:
            id[i+1] = id[i] + 1
        else:
            id[i+1] = id[i]
    num = [[0] * W for i in range(id[H-1]+1)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '1':
                num[id[i]][j] += 1
    for i in range(id[H-1]+1):
        for j in range(W):
            if num[i][j] > K:
                cnt = INF
    sum = [0] * (id[H-1]+1)
    for j in range(W):
        need = False
        for i in range(id[H-1]+1):
            if sum[i] + num[i][j] > K:
                need = True
        if need:
            cnt += 1
            for i in range(id[H-1]+1):
                sum[i] = num[i][j]
        else:
            for i in range(id[H-1]+1):
                sum[i] += num[i][j]
    ans = min(ans, cnt)

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
INF = 110110110
H, W, K = list(map(int, input().split()))
S = [''] * H
for i in range(H):
    S[i] = input()
ans = H * W

for bit in range(2**(H-1)):
    cnt = bin(bit).count('1')
    id = [0] * H
    for i in range(H-1):
        if bit>>i & 1:
            id[i+1] = id[i] + 1
        else:
            id[i+1] = id[i]
    num = [[0] * W for i in range(id[H-1]+1)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '1':
                num[id[i]][j] += 1
    for i in range(id[H-1]+1):
        for j in range(W):
            if num[i][j] > K:
                cnt = INF
    sum = [0] * (id[H-1]+1)
    for j in range(W):
        need = False
        for i in range(id[H-1]+1):
            if sum[i] + num[i][j] > K:
                need = True
        if need:
            cnt += 1
            for i in range(id[H-1]+1):
                sum[i] = num[i][j]
        else:
            for i in range(id[H-1]+1):
                sum[i] += num[i][j]
    ans = min(ans, cnt)

print(ans)
n=int(input())
a=list(map(int,input().split()))
ans=0
r,l=0,0
s,x=0,0
while l<n:
  while r<n and s+a[r]==x^a[r]:
    s+=a[r]
    x^=a[r]
    r+=1
  ans+=r-l
  s-=a[l]
  x^=a[l]
  if r==l:r+=1
  l+=1
print(ans)

ans=0
for i in range(1,n+1):
  for j in range(i+1,n+2):
    p=0
    q=0
    for k in range(i,j):
      p+=c[k]
      q^=c[k]
    ans+=p==q
    if p==q:print(i-1,j-1)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
r,l=0,0
s,x=0,0
while l<n:
  while r<n and s+a[r]==x^a[r]:
    s+=a[r]
    x^=a[r]
    r+=1
  ans+=r-l
  s-=a[l]
  x^=a[l]
  if r==l:r+=1
  l+=1
print(ans)
import copy
s=list(input())
if s[0]=='A' and 'C' in s[2:len(s)] :
  t=copy.copy(s)
  s.remove('A')
  s.remove('C')
  result=''.join(s)
  if len(s)==len(t)-2 and result.islower()==True and t[len(s-1)]!='C':
    print('AC')
  else:
    print('WA')
    
else:
  print('WA')


### FIXED CODE ###

import copy
s=list(input())
if s[0]=='A' and 'C' in s[2:len(s)] :
  t=copy.copy(s)
  s.remove('A')
  s.remove('C')
  result=''.join(s)
  if len(s)==len(t)-2 and result.islower()==True and t[-1]!='C':
    print('AC')
  else:
    print('WA')
    
else:
  print('WA')
x,k,d = [int(x) for x in input().split()]
t = abs(int(x/d))
if x < 0:
    d = -d
if t >= k:
    print(x-d*k)
elif t == 0:
    if k % 2 == 0:
        print(abs(x))
    else:
        print(min(abs(x-d),abs(x+d)))
elif t < k:
    if abs(x-d*t) < abs(x-d*t-d):
        if (t-k)%2==0:
            print(abs(x-d*t))
        else:
            print(min(abs(x-d*t+d),abs(x-d*t-d)))
    elif  abs(x-d*t) = abs(x-d*t-d):
        print(abs(x-d*t))
    else:
        if (t-k-1)%2==0:
            print(abs(x-d*t-d))
        else:
            print(min(abs(x-d*t),abs(x-d*t-2*d)))


### FIXED CODE ###

x,k,d = [int(x) for x in input().split()]
t = abs(int(x/d))
if x < 0:
    d = -d
if t >= k:
    print(abs(x-d*k))
elif t == 0:
    if k % 2 == 0:
        print(abs(x))
    else:
        print(min(abs(x-d),abs(x+d)))
elif t < k:
    if abs(x-d*t) < abs(x-d*t-d):
        if (k-t)%2==0:
            print(abs(x-d*t))
        else:
            print(min(abs(x-d*t+d),abs(x-d*t-d)))
    elif abs(x-d*t) == abs(x-d*t-d):
        print(abs(x-d*t))
    else:
        if (k-t-1)%2==0:
            print(abs(x-d*t-d))
        else:
            print(min(abs(x-d*t),abs(x-d*t-2*d)))
N = int(input())
A = list(int(i) for i in input().split())
B = []
B.append(0)
n = 1
cnt = 0

for i in A:
    B[0] += i
    B.append(B[0])
B[0] = 0
B.sort()

for i in range(1,N+1):
    if B[i] == B[i-1]:
        n += 1
    else:
        cnt += int(n*(n-1)/2)
        n = 1

cnt += int(n*(n-1)/2)6

print(cnt)

### FIXED CODE ###

N = int(input())
A = list(int(i) for i in input().split())
B = []
B.append(0)
n = 1
cnt = 0

for i in A:
    B[0] += i
    B.append(B[0])
B[0] = 0
B.sort()

for i in range(1,N+1):
    if B[i] == B[i-1]:
        n += 1
    else:
        cnt += int(n*(n-1)/2)
        n = 1

cnt += int(n*(n-1)/2)

print(cnt)
n = int(input())
alp = [chr(i) for i in range(97, 97+26)]
ans = []
for i in range(n):
    a = list(input())
    a.sort()
    if i == 0:
        ans = a
    else:
        k = 0
        if len(a) >= len(ans):
            while k < len(a):
                if k >= len(ans):
                    break
                if a[k] < ans[k]:
                    del a[k]
                elif a[k] == ans[k]:
                    k += 1
                elif a[k] > ans[k]:
                    del ans[k]
        else:
            while k < len(ans):
                if k >= len(a):
                    del ans[k]
                    k += 1
                if a[k] < ans[k]:
                    del a[k]
                elif a[k] == ans[k]:
                    k += 1
                elif a[k] > ans[k]:
                    del ans[k]

for i in ans:
    print(i, end="")

### FIXED CODE ###

N = int(input())
s_list = []
s_set = []

for i in range(N):
	s_list.append(list(x for x in input()))

for i in s_list:
	s_set.append(set(i))

result_char = {x for x in 'qwertyuiopasdfghjklzxcvbnm'}

for i in range(N-1):
	result_char = (s_set[i] & s_set[i+1] & result_char)

result_char = list(result_char)
result_char.sort()

result = ''
for i in result_char:
	count = min(x.count(i) for x in s_list)
	result += i*count
print(result)
a,b = map(int, input().split())

c = a*b

if c % 2 == 1:
    print(Odd)

else 
    print(Even)


### FIXED CODE ###

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

if (a*b) % 2 == 1:
    print("Odd")

else:
    print("Even")
# -*- coding: utf-8 -*-

S = input()
T = input()
print(T+S)

### FIXED CODE ###

# -*- coding: utf-8 -*-

S,T = input().split()
print(T+S)
import statistics as stats
from math import factorial


class Comb:
    def __init__(self, N):
        super(Comb, self).__init__()
        self.dic = {}
        for i in range(1, N+1):
            for j in range(1, i+1):
                self.nCr(i, j)

    def nCr(self, n, r):
        if n == r or r == 0:
            return 1
        if self.dic.get((n, r), None) is None:
            self.dic[(n, r)] = self.nCr(n-1, r-1) + self.nCr(n-1, r)
        return self.dic[(n,r)]


def main():
    N, A, B = tuple(map(int, input().split(' ')))
    max_ave = 0
    v_list = sorted(list(map(int, input().split(' '))), reverse=True)

    bucket_min = v_list[A-1]
    max_ = v_list[0]

    max_bucket = v_list[:A]

    max_ave = stats.mean(max_bucket)

    all_bmin_cnt = v_list.count(bucket_min)
    b_bmin_cnt = max_bucket.count(bucket_min)
    all_max_cnt = v_list.count(max_)

    comb = Comb(N)

    print(max_ave)

    if all_max_cnt <= A:
        print(comb.nCr(all_bmin_cnt, b_bmin_cnt))
    else:
        num = 0
        for r in range(A, B+1):
            num += comb.nCr(all_max_cnt, r)
        print(num)




if __name__ == '__main__':
    main()


### FIXED CODE ###

import math


def C(n,r):
    fact = math.factorial
    return fact(n) // fact(r) // fact(n-r)

def main():
    N, A, B = tuple(map(int, input().split(' ')))
    v = list(map(int, input().split(' ')))

    v.sort(reverse=True)

    print(sum(v[:A])/A)

    a, b = v.count(v[A-1]), v[:A].count(v[A-1])

    if v[0] == v[A-1]:
        print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
    else:
        print(C(a, b))



if __name__ == '__main__':
    main()
import math
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
flag = 1
if n % 2 == 0:
    start = 1
else:
    if c[0] != 1:
        flag = 0
    start = 2
for i in range(start, n, 2):
    if c[i] != 2:
        flag = 0
        break
if flag == 0:
    print(0)
else:
    print(int(math.pow(2, n // 2)))


### FIXED CODE ###

n = int(input())
s = list(map(int, input().split()))
s_set = set(s)
count = 2 ** ((n) // 2)
if (sum(s) == 2 * sum(s_set)):
    print(count % (10 ** 9 + 7))
else:
    print(0)
n = int(input())

print((n(n-1)//2))

### FIXED CODE ###

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

ans = 0
for i in range(n):
    if i%2==0:
        ans += a[i]
    else:
        ans -= a[i]

print(ans)
N,M=map(int,input().split())
s=[0]*M
c=[0]*M

for i in range(M):
  s[i],c[i]= map(int,input().split())
  
max_s=max(s)
ans=-1

for j in range(1000):
  flag=True
  k=str(j)
  if len(k)<max_s:
    pass
  else:    
    for l in range(M):
      if int(k[s[l]-1])!=c[l]:
        flag=False
        break
    if flag==True:
      ans=j
      break
      
print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
s=[0]*M
c=[0]*M

for i in range(M):
  s[i],c[i]= map(int,input().split())

if M==0:
  for j in range(1000):
    k=str(j)
    if len(k)==N:
      ans=j
      break
else:
  max_s=max(s)
  ans=-1
  for j in range(1000):
    flag=True
    k=str(j)
    if len(k)!=N:
      pass
    else:
      for l in range(M):
        if int(k[s[l]-1])!=c[l]:
          flag=False
          break
      if flag==True:
        ans=j
        break
      
print(ans)
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i],y[i]=map(int,input(),split())
  ans=x-y+1
  print(ans)

### FIXED CODE ###

N = int(input())
ans=0
for i in range(N):
    l,n= map(int, input().split())
    ans=ans+n-l+1
print(ans)
O,E = map(lambda x: [x2 for x2 in x],input().split())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))
  

### FIXED CODE ###

from sys import stdin
O,E = map(lambda x: [x2 for x2 in x],stdin.read().splitlines())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))
x,y=map(int,input().split())
if x in gp1 and y in gp1:
    print('Yes')
elif x in gp2 and y in gp2 :
    print('Yes')
elif x==y==2:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

gp1=[1,3,5,7,8,10,12]
gp2=[4,6,9,11]

x,y=map(int,input().split())
if x in gp1 and y in gp1:
    print('Yes')
elif x in gp2 and y in gp2 :
    print('Yes')
elif x==y==2:
    print('Yes')
else:
    print('No')
n = int(input())
d_list = list(map(int, input().split()))
d_list.sort(reverse = True)
count = 1

for i in range(1, n):
    if d_list[i] < d_list[i-1]:
        count += 1
print(count)

### FIXED CODE ###

n = int(input())
d_list = [int(input()) for i in range(n)]
d_list.sort(reverse = True)
count = 1

for i in range(1, n):
    if d_list[i] < d_list[i-1]:
        count += 1
print(count)
# -*- coding:utf-8 -*-

if __name__ == "__main__":
    A, B = list(map(int, input().split()))
    ans = 0
    for i in range(A, B+1)
        c = str(i)
        length = len(c)
        if length%2 == 0:
            continue
        for j in range(length):
            if c[j] == c[length-1-j]:
                if j == length-1-j:
                    ans += 1
                    break
                continue
            else:
                break
        print(ans)


### FIXED CODE ###

# -*- coding:utf-8 -*-

if __name__ == "__main__":
    A, B = list(map(int, list(map(float, input().split()))))
    ans = 0
    for i in range(A, B+1):
        c = str(i)
        length = len(c)
        if length%2 == 0:
            continue
        for j in range(length):
            if c[j] == c[length-1-j]:
                if j == length-1-j:
                    ans += 1
                    break
                continue
            else:
                break
    print(ans)
n=int(input())
l=[[]]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
lst=sorted(l,key=lambda x:-x[2])
flag=False

for i in range(0,101):#i=X
    if flag:
        break
    for j in range(0,101):#j=Y
        if flag:
            break
        tmp=lst[0][2]+abs(lst[0][0]-i)+abs(lst[0][1]-j)
        for k in range(n):
            if lst[k][2]!=0:
            #print(k,'ループ目')
                sum=abs(lst[k][0]-i)+abs(lst[k][1]-j)
                H=lst[k][2]+sum
                if tmp!=H :
                    break
                a,b,c=i,j,H
                if k==n-1:
                    flag=True
                    print(i,j,H)
                    break
            else:
                if lst[0][2]!=max(c-abs(a-lst[k][1])-abs(b-lst[k][2])):
                    break
                if k==n-1:
                    flag=True
                    print(i,j,H)
                    break

### FIXED CODE ###

n=int(input())
l=[[]]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
lst=sorted(l,key=lambda x:-x[2])
flag=False

for i in range(0,101):#i=X
    if flag:
        break
    for j in range(0,101):#j=Y
        if flag:
            break
        tmp=lst[0][2]+abs(lst[0][0]-i)+abs(lst[0][1]-j)
        for k in range(n):
            if lst[k][2]!=0:
            #print(k,'ループ目')
                sum=abs(lst[k][0]-i)+abs(lst[k][1]-j)
                H=lst[k][2]+sum
                if tmp!=H :
                    break
                a,b,c=i,j,H
                if k==n-1:
                    flag=True
                    print(i,j,H,)
                    break
            
            else:
                
                if lst[k][2]!=max(c-abs(a-lst[k][0])-abs(b-lst[k][1]),0):
                    #print(c,abs(a-lst[k][0]),abs(b-lst[k][1]))
                    break
                if k==n-1:
                    flag=True
                    print(i,j,H)
                    break
n=int(input())
for i in range(n):
    x,u=map(int,input().split())
    if x[i]=="BTC":
        ans += u[i]*380000.0
    else:
        ans += u[i]
print(ans)


### FIXED CODE ###

n=int(input())
ans=0.0
for i in range(n):
    x,u=input().split()
    if u=="BTC":
        ans += float(x)*380000.0
    else:
        ans += float(x)
print(ans)
a=input()
b=input()
if a<b:
    print("a < b")
elif a>b:
    print("a > b")
else:
    print("a == b")


### FIXED CODE ###

a,b=map(int,input().split())
if a<b:
    print("a < b")
elif a>b:
    print("a > b")
else:
    print("a == b")
n = int(input())
ans = 0
for i in range(n//2):
  ans += 1
printt(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, (n+1)//2):
  ans += 1
print(ans)
a, b, k = map(int, input().split())
l = []

for i in range(1,n+1):
    if a % i == 0 and b % i == 0:
        l.append(i)
print(l[k-1])

### FIXED CODE ###

a, b, k = map(int, input().split())
l = []

for i in range(1,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        l.append(i)
        
print(list(reversed(l))[k-1])
N = int(input)
A = [int(i) for i in input().split()]

a = [20000*i for i in range(N)]
b = [20000*(N-i) for i in range(N)]

for i in range(N):
  a[A[i]-1] += N-i-1

a = [str(i) for i in a]
b = [str(i) for i in b]

print(" ".join(a))
print(" ".join(b))

### FIXED CODE ###

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

a = [20000*i+1 for i in range(N)]
b = [20000*(N-i) for i in range(N)]

for i in range(N):
  a[A[i]-1] += i

a = [str(i) for i in a]
b = [str(i) for i in b]

print(" ".join(a))
print(" ".join(b))
n=int(input())
s=input()
ans=0
for i in range(n):
    for j in range(i,j):
        if s[j] in s[i:j]:
            break
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
l=input()
d=dict()
for a in l:
  if not a in d:
    d[a]=1
  else:
    d[a]+=1
ans=1
for a in d.values():
  ans*=a+1
print((ans-1)%(10**9+7))
A = input()
B = input()
if int(A) <= 8 and int(B) <= 8:
    print('Yay!')
else:
    print(':(')

### FIXED CODE ###

A, B = map(int, input().split())
if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')
N, X, Y = map(int, input().split())

print(N)

for k in range(2, N):
    cnt = 0
    for i in range(1, N + 1):
        if X < i and i + k <= N:
            cnt += 1
        if i <= X and X - i + 1 == k:
            cnt += 2
        if i <= X and X - i + 2 <= k:
            if Y - (k - (X - i + 1)) > i + k:
                cnt += 2
            if Y - (k - (X - i + 1)) == i + k:
                cnt += 1
            if Y + (k - (X - i + 1)) <= N:
                cnt += 1
        if i + k <= X:
            cnt += 1
        if X < i and i+k < Y and:
            if i + k > Y-(k-(i-X+1)) and k-(i-X+1) >= 0:
                cnt += 1
                if Y+(k-(i-X+1)) <= N:
                    cnt += 1
    print(cnt)

### FIXED CODE ###

N, X, Y = map(int, input().split())
dis_comb = [0]*N

for i in range(1, N):
    for j in range(i+1, N+1):
        dis_comb[min(abs(i-j), abs(X-i)+1+abs(Y-j))] += 1

for i in range(1, N):
    print(dis_comb[i])
N = int(input())
V = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N)]
_ = 0
for j in range(N):
  if V[j] > C[j]:
    _ += V[j] - C[j]
print(_)

### FIXED CODE ###

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
_ = 0
for j in range(N):
  if V[j] > C[j]:
    _ += V[j] - C[j]
print(_)
n, k = map(int, input().split())
a = list(map(int, input().split()))
seta = set(a)
dic = {}
for i in seta:
  dic[i] = a.count(i)

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
cnt = 0
for i in range(k):
  cnt = cnt + dic[i][1]

print(n - cnt)

### FIXED CODE ###

n, k = map(int, input().split())
d = {}
for i in input().split():
  if i in d:
    d[i] = d[i] + 1 
  else:
    d[i] = 1

l = sorted(d.values())
print(sum(l[:len(l) - k]))
def main():
    import sys
    input = sys.stdin.buffer.readline
    from collections import Counter as cc
    from fractions import gcd
    n = int(input())
    mod = 10**9 + 7
    C_p,C_n = cc(),cc()
    count= 0
    ans = 1
    for i in range(n):
        a,b = map(int, input().split())
        if a == 0 and b== 0:
            count += 1
        else:
            gcd_ab = gcd(a,b)
            a //= gcd_ab
            b //= gcd_ab
            if b == 0:
                count_zero_b += 1
            elif a == 0: 
                count_zero_a += 1
            else:
                if a/b>0:
                    C_p[a,b] += 1
                else:
                    C_n[a,b] += 1
    count_zero = count
    ans *= (2**count_zero_a + 2**count_zero_b -1)%mod
    count += count_zero_a + count_zero_b    
    for a,b in C_p:
        if (-b,a) in C_n:
            count += C_n[-b,a] + C_p[a,b]
            ans *= (2**C_n[-b,a] + 2**C_p[a,b] -1)%mod
    ans *= pow(2,n-count,mod)%mod
    ans += count -1
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    from collections import Counter as cc
    from fractions import gcd
    n = int(input())
    mod = 10**9 + 7
    C_p,C_n = cc(),cc()
    count= 0
    count_zero_a = count_zero_b = 0
    ans = 1
    for i in range(n):
        a,b = map(int, input().split())
        if a == 0 and b== 0:
            count += 1
        else:
            gcd_ab = gcd(a,b)
            a //= gcd_ab
            b //= gcd_ab
            if b == 0:
                count_zero_b += 1
            elif a == 0: 
                count_zero_a += 1
            else:
                if a/b>0:
                    C_p[a,b] += 1
                else:
                    C_n[a,b] += 1
    count_zero = count
    ans *= (2**count_zero_a + 2**count_zero_b -1)%mod
    count += count_zero_a + count_zero_b    
    for a,b in C_p:
        if (-b,a) in C_n:
            count += C_n[-b,a] + C_p[a,b]
            ans *= (2**C_n[-b,a] + 2**C_p[a,b] -1)%mod
    ans *= pow(2,n-count,mod)%mod
    ans = (ans +count_zero -1) % mod
    print(ans)


if __name__ == '__main__':
    main()
import math
import sys
import numpy as np

#n, a, b= map(int, input().split())
w, h, n  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

x = [0]*n
y = [0]*n
a = [0]*n
for i in range(n):
  x[i], y[i], a[i] = map(int, input().split())
area = np.ones([w,h])

for i in range(n):
  if(a[i] == 1):
    area[:x[i],:] = 0
  if(a[i] == 2):
    area[w-x[i]-1:w,:] = 0
  if(a[i] == 3):
    area[:,:y[i]] = 0
  if(a[i] == 4):
    area[:,h-y[i]-1] = 0

print(np.count_nonzero(area == 1))

### FIXED CODE ###

import math
import sys
import numpy as np

#n, a, b= map(int, input().split())
w, h, n  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

x = [0]*n
y = [0]*n
a = [0]*n
for i in range(n):
  x[i], y[i], a[i] = map(int, input().split())
area = np.ones([w,h])

for i in range(n):
  if(a[i] == 1):
    area[:x[i],:] = 0
  if(a[i] == 2):
    area[x[i]:,:] = 0
  if(a[i] == 3):
    area[:,:y[i]] = 0
  if(a[i] == 4):
    area[:,y[i]:] = 0

print(np.count_nonzero(area == 1))
n, p = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

memo = [[-1] * (n+1) for i in range(n+1)]

def dfs(i, k):
    if memo[i][k] != -1:
        return memo[i][k]
    elif i == 0:
        return min(p + (k+2) ** 2 * X[i] + p, (k + 1) ** 2 * X[i] + p + X[i] + p + 4 * X[i] + p)

    memo[i][k] = min(dfs(i-1, k+1) + p + (k+2) ** 2 * (X[i] - X[i-1]),
                    dfs(i-1, 1) + (k + 1) ** 2 * X[i] + p + X[i] + p + 4 * (X[i] - X[i-1]))

    return memo[i][k]

print(dfs(n-1, 0) + X[-1])

### FIXED CODE ###

n, p = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = []
S = [0]

for x in X:
    S.append(S[-1] + x)

for t in range(1, n+1):
    cur = n - t
    time = 5
    tmp = time * (S[-1] - S[cur]) + (t + n) * p
    cur -= t
    while True:
        tmp += time * (S[cur+t] - S[max(0,cur)])
        if cur <= 0:
            break
        cur -= t
        time += 2

    ans.append(tmp)

print(min(ans))
H,N = map(int,input().split())
M = list(map(int,input().split())

ans = 0       
for i in M:
  ans = ans + i
if h > ans:
  print("No)
else:
  print("Yes")
         

### FIXED CODE ###

H,N = map(int,input().split())
M = list(map(int,input().split()))
 
ans = 0       
for i in M:
    ans = ans + i
if H > ans:
    print("No")
else:
    print("Yes")
N= int(input())
L= list(map(int,input().split()))

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:(i+1)]-L[(i+1):])))

ans=min(v)

print(ans)


### FIXED CODE ###

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

v=[]
for i in range(N-1):
  v.append(abs(sum(L[:i+1])-sum(L[i+1:])))

ans=min(v)

print(ans)