Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
n_shop = int(input())
i_schedule = []
i_benefit = []

max_profit = 0

#開店スケジュールを2進数→10進数に変換
for i in range(n_shop):
    i_schedule.append(int(input().replace(" ",""),2))
    
for i in range(n_shop):
    i_benefit.append(list(map(int,input().split())))
    max_profit += min(i_benefit[i])
    
#全パターンの開店スケジューるの作成
#一つ以上の時間帯で店は開店しなければならない

#schedule=[format(i, '010b') for i in range(1,1024)]
schedule = [i for  i in range(1,1024)]

#そこから一致数の計算→リストのcountメソッドを使う
for sch in schedule:
    anded = []
    for j in range(n_shop):
        anded.append(format(sch & i_schedule[j], "b").count("1"))     #一致スケジュールを2進数表記にして，1の数を計算
        
    profit = sum_benefit(anded)
    
    if max_profit <= profit:
        max_profit = profit
    
        
    

#最後に一致数から利益の計算
def sum_benefit(anded):
    summed= 0
    for shop in range(n_shop):
        sum += i_benefit[shop][anded[shop]]
    return summed

print(max_profit)




### FIXED CODE ###

#標準入力はN,A,Bで与えられる
numbers =input().split()

for  i in range(len(numbers)):
    numbers[i] = int(numbers[i])

if numbers[0]*numbers[1] <= numbers[2]:
    print(numbers[0]*numbers[1])
else:
    print(numbers[2])
import sys
input = sys.stdin.readline

H,W=map(int,input().split())

A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]

SA=[[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        SA[i][j]=abs(A[i][j]-B[i][j])

ZERO=1<<(H+W)
DP=[[1<<ZERO for i in range(W)] for j in range(H)]

DP[0][0]=1<<H+W+SA[0][0]

for i in range(H):
    for j in range(W):
        if i+1<H:
            DP[i+1][j]|=DP[i][j]<<SA[i+1][j]
            DP[i+1][j]|=DP[i][j]>>SA[i+1][j]

        if j+1<W:
            DP[i][j+1]|=DP[i][j]<<SA[i][j+1]
            DP[i][j+1]|=DP[i][j]>>SA[i][j+1]

ANS=1<<30
for i in range((H+W)*2+1):
    if 1<<i & DP[-1][-1]!=0:
        ANS=min(ANS,abs(i-H-W))

print(ANS)


### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W=map(int,input().split())

A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]

SA=[[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        SA[i][j]=abs(A[i][j]-B[i][j])

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

DP[0][0]=1<<(H+W)*80+SA[0][0]

for i in range(H):
    for j in range(W):
        tempbit=DP[i][j]
        if i+1<H:
            DP[i+1][j]|=tempbit<<SA[i+1][j]
            DP[i+1][j]|=tempbit>>SA[i+1][j]

        if j+1<W:
            DP[i][j+1]|=tempbit<<SA[i][j+1]
            DP[i][j+1]|=tempbit>>SA[i][j+1]

ANS=1<<30
for i in range((H+W)*160+1):
    if 1<<i & DP[-1][-1]!=0:
        ANS=min(ANS,abs(i-(H+W)*80))

print(ANS)
H, n = map(int, input().split())
List = [[0 for i in range(4)] for j in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    List[i][0] = b / a
    List[i][1] = b / H
    List[i][2] = a
    List[i][3] = b

def recal():
    for i in range(n):
        b = List[i][3]
        List[i][1] = b / H

sList = sorted(List)
MP = 0
k = 0
while H > 0:
    if sList[k][2] <= H:
        H -= sList[k][2]
        MP += sList[k][3]
        recal()
    else:
        if sList[k + 1][2] <= H:
            if sList[k][1] <= sList[k + 1][0]:
                H -= sList[k][2]
                MP += sList[k][3]
                recal()
                break
            else:
                H -= sList[k + 1][2]
                MP += sList[k + 1][3]
                recal()
                k += 1
        else:
            if sList[k][1] <= sList[k + 1][1]:
                H -= sList[k][2]
                MP += sList[k][3]
                recal()
                break
            else:
                H -= sList[k + 1][2]
                MP += sList[k + 1][3]
                recal()
                k += 1
print(MP)

### FIXED CODE ###

h, a = map(int, input().split())
ans = h // a
if h % a != 0:
    ans += 1

print(ans)
n=int(input())
f=[]
w=[0,0,0,0,0]
for i in range(2,n+1):
    c=0
    r=int(i**0.5)
    for j in range(2,r+2):
        while i%j==0:
            c+=1
            i=i//j
        if c!=0:
            f.append([j,c])
            c=0
    if i!=1:
        f.append([i,1])
f.sort()
d=[]
ans=0
cou=f[0][1]
for i in range(1,len(f)):
    if f[i][0]==f[i-1][0]:
        cou+=f[i][1]
    else:
        d.append(cou)
        cou=1
d.append(cou)

for i in d:
    for j,num in enumerate([2,4,14,24,74]):
        if i>=num:
            w[j]+=1
print(w)
print(w[4]+w[3]*(w[0]-1)+w[2]*(w[1]-1)+w[1]*(w[1]-1)*(w[0]-2)//2)

### FIXED CODE ###

n=int(input())
f=[]
w=[0,0,0,0,0]
for i in range(2,n+1):
    c=0
    r=int(i**0.5)
    for j in range(2,r+2):
        while i%j==0:
            c+=1
            i=i//j
        if c!=0:
            f.append([j,c])
            c=0
    if i!=1:
        f.append([i,1])
f.sort()
d=[]
ans=0
if n!=1:
    cou=f[0][1]
    for i in range(1,len(f)):
        if f[i][0]==f[i-1][0]:
            cou+=f[i][1]
        else:
            d.append(cou)
            cou=1
    d.append(cou)

    for i in d:
        for j,num in enumerate([2,4,14,24,74]):
            if i>=num:
                w[j]+=1
    ans=w[4]+w[3]*(w[0]-1)+w[2]*(w[1]-1)+w[1]*(w[1]-1)*(w[0]-2)//2
print(ans)
D = int(input())
c_list = list(map(int,input().split(' ')))
s_list = []
for i in range(D):
    s_list.append(list(map(int,input().split(' '))))
for day in range(D):
    print(random.randrange(26)+1)
    # maxs = s_list[day].index(max(s_list[day]))
    # print(maxs+1)


### FIXED CODE ###

D = int(input())
c_list = list(map(int,input().split(' ')))
s_list = []
for i in range(D):
    s_list.append(list(map(int,input().split(' '))))
minc = c_list.index(min(c_list))
for d in range(D):
    print(minc+1)
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 += 1
for i in range(q):
    l,r = map(int,input().split())
    print(count[r-1]-count[l-1])

### 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])
K = input()
D = int(input())
L = len(K)
MOD = 10**9+7
dp = [[[0]*D for j in range(2)] for i in range(L+1)] #dp[i][less][modD]
dp[0][0][0] = 1
for i,c in enumerate(K):
    for less in range(2):
        lim = 9 if less else int(c)
        for d in range(lim+1):
            dp[i+1][less or d < lim][(r+d)%D] += dp[i][less][r]
            dp[i+1][less or d < lim][(r+d)%D] %= MOD

print((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)

### FIXED CODE ###

K = input()
D = int(input())
L = len(K)
MOD = 10**9+7
dp = [[[0]*D for j in range(2)] for i in range(L+1)] #dp[i][less][modD]
dp[0][0][0] = 1
for i,c in enumerate(K):
    for less in range(2):
        lim = 9 if less else int(c)
        for r in range(D):
            for d in range(lim+1):
                dp[i+1][less or d < lim][(r+d)%D] += dp[i][less][r]
                dp[i+1][less or d < lim][(r+d)%D] %= MOD

print((dp[-1][0][0] + dp[-1][1][0] - 1) % MOD)
import sys
input = sys.stdin.readline
n,m,p=map(int,input().split())
edge = [[] for i in range(m)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[i]=[a-1,b-1,-c+p]

def sp(s,n,w,es):
  d=[float("inf")]*n
  d[s]=0
  count=0
  ret=[]
  while count<n+1:
    update=False
    for i in range(w):
      e=es[i]
      if d[e[0]]!=float("inf") and d[e[1]]>d[e[0]]+e[2]:
        d[e[1]]=d[e[0]]+e[2]
        update=True
    if not update:
      ret.append(d[-1])
      ret.append(d[-1])
      break
    count+=1
    if count>=n-1:
      ret.append(d[-1])
  return ret
d1,d2=sp(0,n,m,edge)
print(-1 if d1!=d2 else max(0,-d2))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m,p=map(int,input().split())
edge = [[] for i in range(m)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[i]=[a-1,b-1,-c+p]
d=[float("inf")]*n
d[0]=0

for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    d[e1]=min(d[e1],d[e0]+e2)
ans1=d[-1]
for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    if d[e1]>d[e0]+e2:
      d[e1]=-float("inf")
ans2=d[-1]
print(-1 if ans1!=ans2 else max(0,-ans1))
a, b = [int(nv) fo nv in raw_input().split()]
print int(a/b)
print int(a%b)
print a/b

### FIXED CODE ###

a, b = [int(nv) for nv in raw_input().split()]
print "%d %d %f" % (int(a/b), int(a%b), float(a)/b)
a = int(input())
b = int(input())
if a >= 9 or b >= 9:
	print(':(')
else:
	print('Yay!')

### FIXED CODE ###

a,b = map(int,input().split())
if a >= 9 or b >= 9:
	print(':(')
else:
	print('Yay!')
H,W,K = map(int, input().split())
cnt = 0
rep = 1
flg = 0
for i in range(H):
    Lin = input()
    Lin = (Lin.replace("#","1")).replace(".","0")
    if Lin == "0"*W and (i < (H-1)) and flg == 0:
        rep += 1
        pv = str(cnt+1)
    elif Lin == "0"*W :
        print(Str)
    else:
        for j in range(W):
            cnt += int(Lin[j])
            if j == 0:
                Str = pv
            elif Lin[j-1] == "0":
                Str += pv
            elif Lin[j-1] == "1":
                pv = str(int(pv)+1)
                Str += pv
            if j != (W-1):
                Str += " "
        for k in range(rep):
            print(Str)
        rep = 1
        flg = 1

### FIXED CODE ###

H,W,K = map(int, input().split())

def cv(S,cn,pr):
  SS=S
  ans = []
  for i in range(cn):
    ans += [pr+i+1]*(SS.find("#")+1)
    if SS.find("#")<len(SS):
      SS = SS[SS.find("#")+1:]
    else:
      SS = ""
  ans += [pr+cn]*len(SS)
  return ans
    
cnt_pre = 0 #最初のall #no
cnt = 0 # "#"の個数
for i in range(H):
  Lin = input()
  tmp = Lin.count("#")
  if tmp == 0 and cnt == 0:
    cnt_pre +=1
  elif tmp == 0:
    print(*pS)
  else:
    pS = cv(Lin,tmp,cnt)
    for i in range(0,cnt_pre+1):
      print(*pS)
    cnt_pre = 0
  cnt += tmp
if b<=c:
    print(0)
elif d<=a:
    print(0)
elif c>=a and d<=b:
    print(d-c)
elif c>=a and c<=b and d>=b:
    print(b-c)
elif a>=c and a<=d and d<=b:
    print(d-a)
elif a>=c and b<=d:
    print(b-a)
else:
    print(err)

### FIXED CODE ###

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

if min(b,d)-max(a,c)>=0:
    print(min(b,d)-max(a,c))
else:
    print(0)
line = input().split()
a = int( line[0] )
b = int( line[1] )
print( str( a * b ) + " " + str( 2 * ( a + b ) ) )



### FIXED CODE ###

a,b = input().split()
a = int( a )
b = int( b )
print(  a * b, 2 * ( a + b ) )
N = int(input())
S = input()
Q = int(input())
set_dic = {}

for i, s in enumerate(S):
    if s not in set_dic.keys():
        set_dic[s] = {i+1}
    else:
        set_dic[s].add(i+1)

anslist = []

for _ in range(Q):
    query = input()
    if query[0] == "1":
        i = int(query[2])
        c = query[4]
        for l in set_dic.values():
            l.discard(i)
        if c not in set_dic.keys():
            set_dic[c] = {i}
        else:
            set_dic[c].add(i)
    else:
        l = int(query[2])
        r = int(query[4])
        ansset = set()
        for i in range(l, r + 1):
            for key, eachset in set_dic.items():
                if i in eachset:
                    ansset.add(key)
                    break
        ans = len(ansset)
        anslist.append(ans)

for i in anslist:
    print(i)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    S = list(input())
    Q = int(input())
    set_dic = {}

    for i, s in enumerate(S):
        if s not in set_dic:
            set_dic[s] = [i+1]
        else:
            bisect.insort_left(set_dic[s], i+1)

    anslist = []

    for _ in range(Q):
        query1, query2, query3 = input().split()
        if query1 == "1":
            i = int(query2)
            c = query3
            cap = S[i-1]
            if cap == c:
                continue
            set_dic[cap].remove(i)
            if c not in set_dic:
                set_dic[c] = [i]
            else:
                bisect.insort_left(set_dic[c], i)
            S[i-1] = c
        else:
            l = int(query2)
            r = int(query3)
            ansset = set()
            ans = 0
            for eachlist in set_dic.values():
                li = bisect.bisect_left(eachlist, l)
                ri = bisect.bisect_right(eachlist, r)
                if li != ri:
                    ans += 1
            anslist.append(ans)

    for i in anslist:
        print(i)

if __name__ == '__main__':
    solve()
N = int(input())
L = [(N,0),(1,0), (2,1), (4,2), (8,3), (16,4), (32,5), (64,6)]
sorted_L = sorted(L,key=lambda x:x[0])
for i,j in enumerate(sorted_L):
  if j[0] == N:
    if sorted_L[i][0] == sorted_L[i+1][0]:
      print(sorted_L[i][0])
      break
    else:
      print(sorted_L[i-1][0])
      break


### FIXED CODE ###

N = int(input())
L = [(N,0),(1,0), (2,1), (4,2), (8,3), (16,4), (32,5), (64,6),(128,7)]
sorted_L = sorted(L,key=lambda x:x[0])
for i,j in enumerate(sorted_L):
  if j[0] == N:
    if sorted_L[i][0] == sorted_L[i+1][0]:
      print(sorted_L[i][0])
      break
    else:
      print(sorted_L[i-1][0])
      break
D = int(input)
eve = Eve * (25 - D)
print("Christmas" + str(eve))



### FIXED CODE ###

D = int(input())
eve = "Eve " * (25 - D)
print("Christmas " + str(eve))
n, m = map(int, input().split())
for i in range(1, m):
    if m % i == 0:
        if m // i >= n:
            ans = i
        else:
            break
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
ans = 1
for i in range(1, int(m ** .5) + 1):
    if m % i == 0:
        b = m // i
        if i * n <= m:
            ans = max(ans, i)
        if b * n <= m:
            ans = max(ans, b)
print(ans)
if a == 0 and b == 100:
    print(101)
elif a == 1 and b == 100:
    print(10100)
elif a == 2 and b == 100:
    print(1010000)
else:
    print(100**a * b)

### FIXED CODE ###

a, b = [int(x) for x in input().split()]

if b == 100:
    b = 101
    
print(100**a * b)
import math
a,b = map(int , input().split())
i = len(b)
n= pow(10,i)*a+b
m=int(math.sqrt(n))
if m*m=n:
 print("Yes")
else:
 print("No")

### FIXED CODE ###

import math
a,b = map(str , input().split())
i = len(b)
a=int(a)
b=int(b)
n= pow(10,i)*a+b
m=int(math.sqrt(n))
if m*m==n:
 print("Yes")
else:
 print("No")
class coordinates:
  def __init__(self, x, y):
    self.x = x
    self.y = y

def koch(n, a, b):
  if n == 0:
    return
  s = coordinates((2*a[0] + b[0])/3, (2*a[1] + b[1])/3)
  t = coordinates((a[0] + 2*b[0])/3, (a[1] + 2*b[1])/3)
  ux = (t.x - s.x)*cos(pi/3) - (t.y - s.y)*sin(pi/3) + s.x
  uy = (t.x - s.y)*sin(pi/3) + (t.y - s.y)*cos(pi/3) + s.y
 
  koch(n-1, a, s)
  print  s.x, s.y
  koch(n-1, s, u)
  print  u.x, u.y
  koch(n-1, u, t)
  print  t.x, t.y
  koch(n-1, t, b)
 
n = input()
 
p1 = point(0.0, 0.0)
p2 = point(100.0, 0.0)
 
print p1.x, p1.y
koch(n, p1, p2)
print p2.x, p2.y

### FIXED CODE ###

import math

rad = math.radians(60)

class coordinates:
  def __init__(self, x, y):
    self.x = x
    self.y = y
 
def koch(n, a, b):
  if n == 0:
    return
  s = coordinates((2.0*a.x + b.x)/3.0, (2.0*a.y + b.y)/3.0)
  t = coordinates((a.x + 2.0*b.x)/3.0, (a.y + 2.0*b.y)/3.0)
  ux = (t.x - s.x)*math.cos(rad) - (t.y - s.y)*math.sin(rad) + s.x
  uy = (t.x - s.x)*math.sin(rad) + (t.y - s.y)*math.cos(rad) + s.y
  u = coordinates(ux, uy)
  
  koch(n-1, a, s)
  print  s.x, s.y
  koch(n-1, s, u)
  print  u.x, u.y
  koch(n-1, u, t)
  print  t.x, t.y
  koch(n-1, t, b)
  
n = input()
  
p1 = coordinates(0.0, 0.0)
p2 = coordinates(100.0, 0.0)
  
print p1.x, p1.y
koch(n, p1, p2)
print p2.x, p2.y
N = int(input())
P = list(map(int, input().split()))

ans = 0
min = N
for i in range(0, N):
    if i > min:
        continue:
    for j in range(0, i+1):
        if P[i] > P[j]:
            break

        if i == j:
            ans += 1
            min = i

print (ans)



### FIXED CODE ###

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

ans = 0
min_v = P[0]

for i in range(0, N):
    if P[i] <= min_v:
        ans += 1
        min_v = P[i]

print (ans)
A, B = map(int, input().split())
format(A*B, '.0f')

### FIXED CODE ###

def resolve():
    A, B = input().split()
    ans = int(A)*int(B[0])*100+int(A)*int(B[2:])
    print(str(ans)[:-2] if len(str(ans)) >= 3 else "0")
resolve()
op = ["+", "-", "*"]
x = int(raw_input())
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    m = [0,1,2,3]
    m.remove(ii)
    for ii in n:
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == x:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == x:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0

### FIXED CODE ###

op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for ii in n:
        m = [0,1,2,3]
        m.remove(ii)
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0
n = int(input())
A = [0]*n
B = list(map(int, input()))

A[0] = B[0]
A[-1] = B[-1]

for i in range(1, n-1):
  A[i] = min(B[i-1], B[i])
  
print(sum(A))



### FIXED CODE ###

n = int(input())
A = [None for i in range(n)]
B = list(map(int, input().split()))
A[0] = B[0]
A[-1] = B[-1]
 
for i in range(1, n-1):
  A[i] = min(B[i-1], B[i])
print(sum(A))
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

try:
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[i]*(n-p)*2
    


except:
    print(0)

ans+=(m-cnt)*md
print(ans)

### FIXED CODE ###

import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

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

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

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

import itertools
n = inn()
a = inl()
if n>300:
    3/0
cms = itertools.combinations(list(range(1,n)),3)
ans = BIG
for cm in cms:
    v = []
    v.append(sum(a[:cm[0]]))
    v.append(sum(a[cm[0]:cm[1]]))
    v.append(sum(a[cm[1]:cm[2]]))
    v.append(sum(a[cm[2]:]))
    ans = min(ans,max(v)-min(v))
print(ans)


### FIXED CODE ###

#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

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

import bisect
n = inn()
a = inl()
lacc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+a[i]
ans = BIG
for i in range(2,n-1):
    j = bisect.bisect_left(lacc,lacc[i]//2+1)
    j = min(j,i-1)
    k = bisect.bisect_left(lacc,(lacc[n]+lacc[i])//2+1)
    k = min(k,n-1)
    for dj in range(2):
        jj = j-dj
        if jj<=0:
            continue
        for dk in range(2):
            kk = k-dk
            if kk<=i:
                continue
            v = []
            v.append(lacc[jj])
            v.append(lacc[i]-lacc[jj])
            v.append(lacc[kk]-lacc[i])
            v.append(lacc[n]-lacc[kk])
            ans = min(ans,max(v)-min(v))
print(ans)
N = int(input())
D = sorted(list(map(int,input().split())))
MOD = 998244353

ans = 1
count = {}
for i in range(N):
  if i < D[i] or (i > 0 and D[i] == 0):
    print(0)
    exit()
  else:
    if D[i] in count:
      count[D[i]] += 1
    else:
      count[D[i]] = 1
    if D[i] > 0:
      ans *= count[D[i]-1]
      ans %= MOD
print(ans)

### FIXED CODE ###

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

if D[0] != 0:
  print(0)
  exit()

D.sort()
ans = 1
count = {}
for i in range(N):
  if i > 0:
    if D[i]-1 in count:
      ans *= count[D[i]-1]
      ans %= MOD
    else:
      print(0)
      exit()
  if D[i] in count:
    count[D[i]] += 1
  else:
    count[D[i]] = 1
print(ans)
n=int(input())
a=list(map(int,input().split()))
ans=0

while all(i%2==0 for i in a):
    ans+=1
    for j in range(n):
        a[i]//=2
print(ans)


### FIXED CODE ###

n=int(input())
c=32
for i in input().split():
    d=0
    z=int(i)
    while z%2==0:
        d+=1
        z=z//2
    if d<c:
        c=d

print(c)
if N < 105:
    print(0)
elif N < 165:
    print(1)
elif N < 195:
    print(2)
else:
    print(3)

### FIXED CODE ###

N = int(input())

if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 189:
    print(3)
elif N < 195:
    print(4)
else:
    print(5)