Harryxun/stf_run huggingface dataset:
def solve(d,c,s,k):
    last=[0]*27
    srate=[]
    ans=[]
    for i in range(1,d+1):
        a=0
        for j in range(1,27):
            a-=c[j-1]*(i-last[j])
        pa=0
        mlast=[0]*2
        for t in range(1,27):
            if s[i-1][t-1]+c[t-1]*(min(k*(k-1)/2,(366-d)*((366-d)-1)/2))>pa:
                mlast=[t,i]
                pa=s[i-1][t-1]+c[t-1]*(i-last[t])
        a+=pa
        last[mlast[0]]=mlast[1]           
        ans.append(mlast[0])
        srate.append(a)
    return ans,srate

def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    mrate=0
    for i in range(26):
        a,srate=solve(d,c,s,13)
        if mrate<srate[-1]:
            ans=a
            mrate=srate[-1]
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    last=[0]*27
    ans=[]
    for i in range(1,d+1):
        a=0
        for j in range(1,27):
            a-=c[j-1]*(i-last[j])
        pa=0
        mlast=[0]*2
        for t in range(1,27):
            if s[i-1][t-1]+c[t-1]*(i-last[j])>pa:
                mlast=[t,i]
                pa=s[i-1][t-1]+c[t-1]*(i-last[j])
        a+=pa
        last[mlast[0]]=mlast[1]           
        ans.append(mlast[0])
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()
s=list(map(input()))
k=[]
if len(s)%2==0:
   for i in range(len(s)/2):
       k.append(s[2*i])
else:
    for i in range((len(s)//2)+1):
        k.append(s[2*i])
print("".join(k))

### FIXED CODE ###

s = list(input())
k = s[::2]
print("".join(k))
import math
N = int(input())
h = list(map(int, input().split()))


def recursive(i):
    if i == 0:
        return 0
    res = math.inf
    res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    return res


print(recursive(N - 1))


### FIXED CODE ###

import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])
import sys
sys.setrecursionlimit(100000)
# N = 4
# ARR = [10, 30, 40, 20]

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

def calculate(n, arr):
    result = aaa(0, n - 1, arr)
    print(result)


def aaa(currentPosition, endPosition, arr, cost=0):
    if currentPosition == endPosition:
        return cost
    if currentPosition == (endPosition - 1):
        return aaa(endPosition, endPosition, arr, cost + abs(arr[endPosition] - arr[currentPosition]))

    a1 = abs(arr[currentPosition + 1] - arr[currentPosition])
    a2 = abs(arr[currentPosition + 2] - arr[currentPosition])

    s1 = aaa(currentPosition + 1, endPosition, arr, cost + a1)
    s2 = aaa(currentPosition + 2, endPosition, arr, cost + a2)
    return min(s1, s2)





calculate(N, ARR)


### FIXED CODE ###

# N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]

N = int(input())
HRR = list(map(int,input().split()))
result = []
for i in range(N):
    if i == 0:
        result.append(0)
    elif i == 1:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        result.append(s1)
    else:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
        result.append(min(s1, s2))

print(result[-1])
import math
N = int(input())
ans = 0
for i in range(1,10):
    for j in range(1,10):
        c1 = 0
        c2 = 0
        for x in range(1,N+1):
            d = 10 ** int(math.log10(x)) 
        
            if x % 10 == i and x // d == j:
                c1 += 1
            if x % 10 == j and x // d == i:
                c2 += 1
        ans += c1 * c2

print (ans)

### FIXED CODE ###

N,M = map(int,input().split())
if N == M:
  print ('Yes')
else:
  print ('No')
a,b,c=int(input())
if a-b>=c:
  print(0)
else:
  print(c-(a-b))

### FIXED CODE ###

a,b,c=map(int,input().split())
if a-b>=c:
  print(0)
else:
  print(c-(a-b))
import random
random.seed(0)

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

def score_calc(T):
    total = 0
    last = [0] * 26
    for i in range(1, D+1):
        t = T[i-1]
        total += S[i-1][t-1]
        last[t-1] = i
        for j in range(26):
            total -= C[j] * (i - last[j])
    return total
    
N = 100
T_ls = [[random.randint(1, 26) for i in range(D)] for j in range(N)]
best_score = 0
ans = []
for i in range(N):
    if score_calc(T_ls[i]) > best_score:
        best_score = score_calc(T_ls[i])
        ans = T_ls[i]

for i in range(D):
    print(ans[i])

### FIXED CODE ###

D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t-1]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

for i in range(D):
    print(ans[i])
K = int(input())
A, B = map(int, input().split())
isCompelte = False

for i in range(A,B+1):
  if i % K == 0:
    isComplete = True
    break

if isComplete:
  print("OK")
else:
  print("NG")

### FIXED CODE ###

K = int(input())
A, B = map(int, input().split())
flag = 0

for i in range(A,B+1):
  if i % K == 0:
    flag = 1

if flag == 1:
  print("OK")
else:
  print("NG")
a=input()
b=input()
c=input()
if(a+b+c) %2==0:
    print("bust")
else:
    print("win")

### FIXED CODE ###

a = [int(i) for i in input().split(" ")]
print("bust") if sum(a) >= 22 else print("win")
n = print()

s = int(n) % 10

if s == 3:
  print('bon')
if s == 1:
  print('pon')
if s == 2:
  print('hon')
if s == 4:
  print('hon')
if s == 5:
  print('hon')
if s == 6:
  print('pon')
if s == 7:
  print('hon')
if s == 8:
  print('pon')
if s == 9:
  print('hon')
if s == 0:
  print('pon')

### FIXED CODE ###

N = input()
s = int(N) % 10
if s == 3:
    print('bon')
if s == 0:
    print('pon')
if s == 1:
    print('pon')
if s == 6:
    print('pon')
if s == 8:
    print('pon')

if s == 2:
    print('hon')
if s == 4:
    print('hon')
if s == 5:
    print('hon')
if s == 7:
    print('hon')
if s == 9:
    print('hon')
import math
num_max = 1000
isPrimeNum = [True for i in range(0,num_max)]

isPrimeNum[0] == False
isPrimeNum[1] == False

for i in range(2, int(math.sqrt(num_max))):
    if isPrimeNum[i] == True:
        for j in range (i**2, num_max, i):
            isPrimeNum[j] = False
        


num_len = int(input())
cnt = 0

for i in range(num_len):
    num = int(input())
    if isPrimeNum[num]==True:
        cnt = cnt + 1

print(str(cnt))

### FIXED CODE ###

def isPrimeNum(in_num):
    if in_num <= 1:
        return False
    elif in_num == 2:
        return True
    elif in_num % 2 == 0:
        return False
    else:
        if pow(2, in_num-1, in_num) == 1:
            return True
        else:
            return False


num_len = int(input())
cnt = 0
for i in range(num_len):
    num = int(input())
    if isPrimeNum(num)==True:
        cnt = cnt + 1

print(str(cnt))
s=input()
k=int(input())
c=0
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
if s[0]==s[-1]:
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    for i in range(len(b)-1):
      r+=(b[i+1]//2)*k
    print(r+b[0]+b[-1]+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)

### FIXED CODE ###

s=input()
k=int(input())
c=1
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
    c=1
if s[0]==s[-1]:
  b.append(c)
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    if len(b)>=2:
      for i in range(len(b)-2):
        r+=(b[i+1]//2)*k
    print(r+b[0]//2+b[-1]//2+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)
s =input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
  
else:
  print"No")


### FIXED CODE ###

s =list(input())
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
  
else:
  print("No")
n = int(input())
dv = []
dved = []
for i in range(1,n):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1])))


### FIXED CODE ###

import math
n = int(input())
dv = []
dved = []
for i in range(1,int(math.sqrt(n)+1)):
    if n%i==0 and not(i in dved):
        dv.append(i)
        dved.append(n//i) 
    if i in dved:
        break
print(len(str(dved[-1]))if len(dv)>0 else 1)
s=input()
S=list(s)
cc=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cc=cc+1
S.remove('C')
S.remove(S[0])
count=[]
if s[0]=='A':
  count.append(1)
if cc==1:
  count.append(2)
if ''.join(S).islower():
  count.append(3)

if count==[1,2,3]:
  print('AC')
else:
  print('WA')

### FIXED CODE ###

s=input()
S=list(s)
cc=0
for i in range(2,len(S)-1):
  if S[i]=='C':
    cc=cc+1
if cc>=1:
  S.remove('C')
S.remove(S[0])
count=[]
if s[0]=='A':
  count.append(1)
if cc==1:
  count.append(2)
if ''.join(S).islower():
  count.append(3)

if count==[1,2,3]:
  print('AC')
else:
  print('WA')
while 1:
    try : line = raw_input()
    except : break
    for i in range(26):
        char = chr(i + 97)
          print '%s : %d' % (char , line.lower().count(c))

### FIXED CODE ###

line = ""
while True:
    try: line += raw_input()
    except:break
for i in range(26):
    c = chr(i + 97)
    print '%s : %d' % (c, line.lower().count(c))
from collections import deque

h,w = map(int,input().split())
maze = []

for _ in range(h):
    maze.append(input())

ans = 0

move = [[1,0],[-1,0],[0,1],[0,-1]]

for i in range(h):
    for j in range(w):
        if(maze[i][j]=="."):
            dist = np.ones((h,w))*99999999
            
            dq = deque()
            y=i
            x=j
            d=0
            
            dq.append((y,x,d))
            
            while(len(dq)):
                
                y,x,d = dq.popleft()
                dist[y][x]=d
                for m in move:
                    if((0<=x+m[0]<w) and (0<=y+m[1]<h) and
                        (dist[y+m[1]][x+m[0]] > d+1) and
                            (maze[y+m[1]][x+m[0]] == ".")):
                                dq.append((y+m[1],x+m[0],d+1))
                                
            ans = max(ans,d)
            # print(d,i,j)
print(ans)

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())
maze = []

for _ in range(h):
    maze.append(input())

ans = 0

move = [[1,0],[-1,0],[0,1],[0,-1]]

for i in range(h):
    for j in range(w):
        if(maze[i][j]=="."):
            dist = [ [99999999]*w for _ in range(h) ]
            
            dq = deque()
            y=i
            x=j
            d=0
            dist[y][x]=0
            dq.append((y,x,d))
            
            while(len(dq)):
                
                y,x,d = dq.popleft()
                
                for m in move:
                    if((0<=x+m[0]<w) and (0<=y+m[1]<h) and
                        (dist[y+m[1]][x+m[0]] > d+1) and
                            (maze[y+m[1]][x+m[0]] == ".")):
                                dist[y+m[1]][x+m[0]]=d+1
                                dq.append((y+m[1],x+m[0],d+1))
                                
            ans = max(ans,d)
            # print(d,i,j)
print(ans)
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    a = []
    while True:
        l = input()
        if l:
            a.append(l)
        else:
            break

    args = '\n'.join(a)
    points = [s.split(' ') for s in a[1:]]

    main(
        int(a[0]),
        [(int(p[0]), int(p[1])) for p in points]
    )


### FIXED CODE ###

import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    n = int(input())
    a = [input() for i in range(n)]

    points = [s.split(' ') for s in a]

    main(
        n,
        [(int(p[0]), int(p[1])) for p in points]
    )
aaa = [int(input()) for i in range(5)]

i = list()
b = 0
for a in aaa:
  n = 0
  n = 10 - int(str(a)[-1])
  if n % 10 != 0:i.append(n)
print(sum(aaa) + sum(i) - max(i))

### FIXED CODE ###

aaa = [int(input()) for i in range(5)]

i = list()
b = 0
for a in aaa:
  n = 0
  n = 10 - int(str(a)[-1])
  if n % 10 != 0:i.append(n)
    
if len(i) == 0:
  h = 0
else:
  h = max(i)
print(sum(aaa) + sum(i) - h)
N=int(input())
A=list(map(int,input().split()))
A.sort()
INF=1e9+7
if N%2==1:
    if A[0]!=0:
        print(0)
        quit()
    for i in range((N-1)//2):
        if A[2*i+1]!=2*(i+1) or A[2*i+2]!=2*(i+1):
            print(0)
            quit()
    print(2**((N-1)//2)%INF)
else:
    for i in range(N//2):
        if A[2*i]!=2*i+1 or A[2*i+1]!=2*i+1:
            print(0)
            quit()
    print(2**(N//2)%INF)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
INF=int(1e9+7)
if N%2==1:
    if A[0]!=0:
        print(0)
        quit()
    for i in range((N-1)//2):
        if A[2*i+1]!=2*(i+1) or A[2*i+2]!=2*(i+1):
            print(0)
            quit()
    print(2**((N-1)//2)%INF)
else:
    for i in range(N//2):
        if A[2*i]!=2*i+1 or A[2*i+1]!=2*i+1:
            print(0)
            quit()
    print(2**(N//2)%INF)
a,b=map(int,input().split)
if a < b :
    print("a < b")
elif a > b :
    print("a > b")
else a == b:
    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, M = map(int, input().split())
X = [0] * M
Y = [0] * M
Z = [0] * M 
unique = []
count = 0
for i in range(M):
  X[i], Y[i], Z[i] = map(int, input().split())

reach = [[] for _ in range(N)]
for i in range(M) :
    reach[Y[i]-1].append(X[i])
    reach[X[i]-1].append(Y[i])

approach = [False for _ in range(N)]

i = 1

ans = 0

def change(reach, s):       
    approach[s-1] = True
    for i in reach[s-1]:
        if not approach[i-1] :
            change(reach, i)

for i in range(N) :
    if not approach[i]:
        change(reach, i)
        ans += 1

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N,M = list(map(int,input().split()))
XYZ = [list(map(int,input().split())) for _ in range(M)]

G = [[] for _ in range(N)]
 
for i in XYZ:
    G[i[0]-1].append(i[1])
    G[i[1]-1].append(i[0])
 
check = [False for _ in range(N)]
 
def DFS(G,s):
    check[s-1] = True
    for i in G[s-1]:
        if not check[i-1]:         
            DFS(G,i)
ans = 0
for i in range(N):
    if not check[i]:
        DFS(G,i+1)
        ans += 1

print(ans)
r1, c1, r2, c2 = map(int, input().split())

MOD = 10**9+7
n = max(r1, c1, r2, c2)
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

w = r2 - r1
h = c2 - c1
X, Y = 0, 0
ans = comb(c1+r1, r1)
for i in range(c1+1, c2+1):
    ans += comb(i+r1, r1)
    X += (h-(i-(c1+1)))*comb(i+r1, r1)
for i in range(r1+1, r2+1):
    ans += comb(i+c1, c1)
    Y += (w-(i-(r1+1)))*comb(i+c1, c1)
ans += w*X+h*Y
ans %= MOD
print(ans)

### FIXED CODE ###

def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+2
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    def f(r, c):
        return comb(r+c+2, c+1)

    ans = f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    solve()
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(len(values)):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(len(values)):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(len(gcd_from_the_left)):
  if i==0:
    gcd = gcd_from_the_right[-2]
  if i==len(gcd_from_the_left):
    gcd = gcd_from_the_left[i]
  if 0<i<len(gcd_from_the_left):
    gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[len(gcd_from_the_left)-i-2])
  if gcd > ans:
    ans = gcd
print(ans)


### FIXED CODE ###

#スペース区切りの整数の入力
A, B, T= map(int, input().split())
ans = (int(T/A))*B
print("{}".format(ans))
s = input()

if s == "ABC":
  ans = "ARC"
 else:
  ans = "ABC"
  
 print(ans)

### FIXED CODE ###

s = input()

if s == "ABC":
  ans = "ARC"
else:
  ans = "ABC"
  
print(ans)
s = input() 
day = ['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1]
dic = {d:i+1 in i,d zip(range(len(day),day))}
print(dic[s])

### FIXED CODE ###

day = ['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1]
dic = {d:i+1 for i,d in zip(range(len(day)),day)}
print(dic[input()])
a = input().split(" ")
s = [input() for i in range(a)]
print("".join(sorted(s))

### FIXED CODE ###

a = input().split(" ")
s = [input() for i in range(int(a[0]))]
print("".join(sorted(s)))
#!/usr/bin/env python3
l = [input() for _ in range(5)]
m = 9
ans = 0
for i in range(len(l)):
    n = int(l[i][-1])
    if n == 0: n = 10
    if n < m:
        m = n
        ind = i
for t in range(len(l)):
    if t == ind:
        ans += int(l[t])
    else:
        n = int(l[t][-1])
        if n == 0: n = 10
        ans += (int(l[t]) + 10 - n)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
l = [input() for _ in range(5)]
m = 11
ans = 0
for i in range(len(l)):
    n = int(l[i][-1])
    if n == 0: n = 10
    if n < m:
        m = n
        ind = i
for t in range(len(l)):
    if t == ind:
        ans += int(l[t])
    else:
        n = int(l[t][-1])
        if n == 0: n = 10
        ans += (int(l[t]) + 10 - n)
print(ans)
n=int(input())
listA=(input().split())
list1=[0 for i in range(n)]
list2=[]
numOfBox=0
#考えるべきボールの数の合計
for i in range(n,0,-1):#n,n-1,...1って感じです
    #print(i)
    count=1
    s=0
    while i*count<=n:
        s+=list1[i*count-1]
        count+=1
    #print(s)
    if s%2!=int(listA[i-1]):
        list1[i-1]+=1
        numOfBox+=1
        list2.append(i)
#print(list1)
print(numOfBox)
for i in range(len(list2)):
    print(list2[i],end=" ")

### FIXED CODE ###

r=int(input())
m=3*r*r
print(m)
n=int(input())
s=input()
cnt=len(s)
a='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans=''
for i in range(cnt):
  ans=ans+a[i+n]
print(ans)  


### FIXED CODE ###

n=int(input())
s=input()
cnt=len(s)
a='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans=''
for i in range(cnt):
  
  l=a.index(s[i])
  ans=ans+a[(l+n)%26]
print(ans)
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
bi = [0]*(A[0]+1)
for a in A:
  bi[a]+=1
  
cum = [0]*(A[0]+1)
for i in range(1,A[0]+1):
  cum[i]=cum[i-1]+bi[i]

cum_max=cum[-1]
left = 0
right = A[0]*2
while right-1!=left:
  x = (right+left)//2
  num = 0
  for a in A:
    b = max(x-a,1)
    if b<=A[0]:
      num += cum_max-cum[b-1]
    
  if num>M:
    left=x
  else:
    right=x
ans = 0
cum_A = [0]*(N+1)
for i in range(1,N+1):
  cum_A[i]=cum_A[i-1]+A[i-1]
for a in A:
  b = max(left-a,1)
  if b>A[0]:
    break
  c = cum_max-cum[b-1]
  M-=c
  ans+=(a*c)+cum_A[c]
  

ans+=(M*left)
if M==0:
  print(ss)
print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
bi = [0]*(A[0]+1)
for a in A:
  bi[a]+=1
  
cum = [0]*(A[0]+1)
for i in range(1,A[0]+1):
  cum[i]=cum[i-1]+bi[i]

cum_max=cum[-1]
left = 0
right = A[0]*2+1
while right-1!=left:
  x = (right+left)//2
  num = 0
  for a in A:
    b = max(x-a,1)
    if b<=A[0]:
      num += cum_max-cum[b-1]
    
  if num>=M:
    left=x
  else:
    right=x

ans = 0
cum_A = [0]*(N+1)
for i in range(1,N+1):
  cum_A[i]=cum_A[i-1]+A[i-1]
for a in A:
  b = max(right-a,1)
  if b>A[0]:
    break
  c = cum_max-cum[b-1]
  M-=c
  ans+=(a*c)+cum_A[c]
  

ans+=M*left
print(ans)
A = input()
B = input()
A = int(A)
B = int(B)

if (A+B) % 2 == 0:
    print((A+B)//2)
else:
    print("IMPOSSIBLE")
    

### FIXED CODE ###

A, B = input().split()
A = int(A)
B = int(B)

if (A+B) % 2 == 0 and A != B:
    print((A+B)//2)
else:
    print("IMPOSSIBLE")
N = input()
if N % 2 == 1:
  print(((N + 1)/2)/N)
else:
  print((N/2/)N)

### FIXED CODE ###

N = int(input())
if N % 2 == 1:
  print((int(N/2) + 1)/N)
else:
  print(0.5)
def fatora(n):
	ans = []
	for i in range(1, n+1):
		if i*i > n:
			break
		if n % i == 0:
			ans.append(i)
			ans.append(n//i)
	ans.sort()
	return set(ans)

def eh_primo(n):
	if n <= 1:
		return True
	elif n == 2:
		return True
	else:
		for i in range(2, n+1):
			if i*i > n:
				break
			else:
				if n % i == 0:
					return False
		return True
	


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

new_gcd = math.gcd(a, b)

list_div = fatora(new_gcd)
list_primes = list(filter(eh_primo, list_div))

print(len(list_primes))

### FIXED CODE ###

def fatora(n):
	ans = []
	for i in range(1, n+1):
		if i*i > n:
			break
		else:
			if n % i == 0:
				ans.append(i)
				ans.append(n//i)
	return set(ans)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)


def eh_primo(n):
	if n == 0:
		return False
	elif n == 1:
		return True
	elif n == 2:
		return True
	else:
		for i in range(2, n+10):
			if i*i > n:
				break
			else:
				if n % i == 0:
					return False
		return True



a, b = map(int, input().split())
print(len(list(filter(eh_primo, fatora(gcd(a, b))))))
n = int(input())
flag = 0
list = [int(x) for x in input().split()]
for i in range(1, n):
  if flag == n:
    break
  else:
    m = list[i-1:].count(i)
    flag += m
    print(m)
print(0)

### FIXED CODE ###

r =int(input())
print(6.28*r)
N, M = map(int, input().split())
S = input()
T = input()

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))
L = lcm(N, M)
X = ['0'] * L

for i in range(0,N):
	X[i*L//N] = S[i]
for i in range(0,M):
	if X[i*L//M] != '0':
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(lcm(N, M))


### FIXED CODE ###

N, M = map(int, input().split())
S = input()
T = input()

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))


L = lcm(N, M)
X = {}


for i in range(0,N):
	X[i*L//N] = S[i]
# print(X)
for i in range(0,M):
	if X.get(i*L//M) != None:
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(L)
li = list(map(int,input().split()))
li[0] = a
li[4] = e
li[5] = k

if e - a < k:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a <= k:
    print("Yay!")
else:
    print(":(")