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

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)
    else:
        um=m-1
        m=int((um+lm)//2)
    if rf(m)==(n+k) and um-lm<5:
        break

for mi in range(m+5,m-10,-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
        break

print(mi)

### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
H,W=map(int, input().split())
S = []

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(input())+['.'])
S.append(['.']*(W+2))

ans = "Yes"

# 内部
for i in range(1,W+1):
    for j in range(1,H+1):
        if S[i][j] == "#":
            if S[i-1][j] == "." and S[i+1][j] == "." and  S[i][j-1] == "." and  S[i][j+1]== ".":
                print("No")
                sys.exit()

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
H,W=map(int, input().split())
S = []

S.append(['.']*(W+2))
for _ in range(H):
    S.append(['.']+list(input())+['.'])
S.append(['.']*(W+2))

for i in range(1,H-1):
    for j in range(1,W-1):
        if S[i][j] == "#" and S[i-1][j] == "." and S[i+1][j] == "." and  S[i][j-1] == "." and  S[i][j+1]== ".":
            print("No")
            sys.exit()

print("Yes")
from collections import deque

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

G=[[] for i in range(M+1)]

for i in range(M):
    n,m=map(int,input().split())
    G[n].append(m)
    G[m].append(n)

visited=[0]*(N+1)
ans=0
def dfs(now, num_visited=0):
    global ans
    visited[now] = 1
    num_visited+=1
    
    if num_visited==N:
        ans+=1
    
    for i in G[now]:
        next=i
        if visited[next]!=1:dfs(next,num_visited)
        
    visited[now] = 0

dfs(1)
print(ans)

### FIXED CODE ###

from collections import deque

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

G=[[] for i in range(N+1)]

for i in range(M):
    n,m=map(int,input().split())
    G[n].append(m)
    G[m].append(n)

visited=[0]*(N+1)
ans=0
def dfs(now, num_visited=0):
    global ans
    visited[now] = 1
    num_visited+=1
    
    if num_visited==N:
        ans+=1
    
    for i in G[now]:
        next=i
        if visited[next]!=1:dfs(next,num_visited)

    visited[now] = 0

dfs(1)
print(ans)
import random

N = input()
1<= N(int) <=100

if N(int) % 2 ==0:
  print(1/2)

else:
  N(int) % 2 !=0:
  x = N(int)- (N(int)+1)/2
  print(x/N(int))


### FIXED CODE ###

N = input()
1 <= int(N) <= 100

if int(N) % 2 == 0:
  print(float(1/2))

else:
  x = (int(N)+1)/2
  print(float(x/int(N)))
import math
from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

def lcm(a, b):
    return a // math.gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

F = set()
for a in A:
    F.add(f(a))
if(len(F) != 1):
    print(0)
    exit()

l = reduce(lcm, A)
ans = - (- (m // 2) // l)
print(ans)

### FIXED CODE ###

from functools import reduce
def f(n):
    res = 0
    while(n%2 == 0):
        res += 1
        n //= 2
    return res

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

def lcm(a, b):
    return a // gcd(a, b) * b

n, m = map(int, input().split())
A = list(map(lambda x: int(x) // 2, input().split()))

l = reduce(lcm, A, 1)
for a in A:
    if((l // a) % 2 == 0):
        print(0)
        break

else:
    ans = (m // l +1) // 2
    print(ans)
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    SUM += combinations_count(v,2)

print(SUM)

### FIXED CODE ###

from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    if v > 1:
        SUM += combinations_count(v,2)

print(SUM)
N = int(input())
s  = input().strip()

S = set()
for c in combinations(range(N), N-3):
    i0 = 0; x = ''
    for i in c:
        x += s[i0:i]
        i0 = i+1
    x += s[i0:]
    S.add(x)                                  
print(len(S))   #; print(S) 

### FIXED CODE ###

N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1
            else:
                continue
        else:
            continue        
    else:
        continue
                                   
print(cnt)
int main() {
    int a, b;
    cin >> a >> b;
    int c = a * b;
    if (c % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}

### FIXED CODE ###

i = list(map(int, input().split()))
a=i[0]+i[1]
b=i[0]-i[1]
c=i[0]*i[1]
if a>=b and a>=c:
  print(a)
elif b>=a and b>=c:
  print(b)
else:
  print(c)
n = int(input())
p = list(map(int,input().split()))
cnt = 1
m = p[1]

for i in p:
    if i <= m:
        m = i
        cnt += 1


print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
cnt = 0
t = p[0]

for i in range(n):
    if t >= p[i]:
        cnt += 1
        t = p[i]


print(cnt)
#112_D
N,M=map(int,input().split())
#M//N以下のMの約数の最大
divisors=[]
for i in range(1,int(M**.5)+1):
    if M%i==0:
        divitors.append(i)
        if i!=(M//i):
            divitors.append(M//i)
Ans=1
for x in divitors:
    if M//N>=x:
        Ans=x
    else:
        break
print(Ans)

### FIXED CODE ###

#112_D
N,M=map(int,input().split())
#M//N以下のMの約数の最大
divisors=[]
for i in range(1,int(M**.5)+1):
    if M%i==0:
        divisors.append(i)
        if i!=(M//i):
            divisors.append(M//i)
Ans=1
for x in sorted(divisors):
    if M//N>=x:
        Ans=x
    else:
        break
print(Ans)
s = int(input())
print("Yes" if all((i%2==0 and s[i] in "RUD") or (i%2!=0 and s[i] in "LUD") for i in range(len(s))) else "No")

### FIXED CODE ###

s=input()
print("Yes" if all((i%2==0 and s[i] in "RUD") or (i%2!=0 and s[i] in "LUD") for i in range(len(s))) else "No")
def solve(n, y):
    for man in range(0, n + 1):
        for gosen in range(0, n - man + 1):
            sen = n - man - gosen
            if 10000*man + gosen*5000 + sen*1000 == y and man + gosen + sen == n:
                print('{} {} {}'.format(man, gosen, sen))
                return 0
    print("-1 -1 -1")
    return 0            

#main
n = int(input())
y = int(input())
solve(n, y)




### FIXED CODE ###

def solve(n, y):
    for man in range(n + 1):
        for gosen in range(n - man + 1):
            sen = n - man - gosen
            if 10000*man + gosen*5000 + sen*1000 == y and man + gosen + sen == n:
                print('{} {} {}'.format(man, gosen, sen))
                return
    print("-1 -1 -1")
    return            

#main
n, y = map(int, raw_input().split())
solve(n, y)
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : x[1],reverse=True)

import bisect
ans = 0
c = 0
sA= sorted(A)
for i in range(M):
    if -bc[i][0] - c > N + 1:
        c = -bc[i][0] + N + 1
    if A[-bc[i][0]-c] > bc[i][1]:
        cc = bisect.bisect_left(sA,bc[i][1])
        ans += (bc[i][1]*(cc-c))
        c += (cc-c)
        break
    else:
        c += bc[i][0]
        ans += (bc[i][1]*bc[i][0])

for i in range(N):
    if i < N - c:
        ans += A[i]
    else:
        break
print(ans)


### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
    for j in range(i,min(N,i+b)):
        if A[j] < c:
            A[j] = c
    i += b
print(sum(A))
from math import factorial
class UnionFind:
    def __init__(self, size):
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = N*(N-1)//2
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        unconv -= abs(u.table[u.find(q[0]-1)]*u.table[u.find(q[1]-1)])
        if unconv<0:
            unconv = 0
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)

### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        import sys
        sys.setrecursionlimit(10**5)
        """
        リストの添字を集合の値として利用し
        リストの要素を根, 節の管理に用いる
        要素が負の添字は素集合の根であり、集合の要素数
        要素が0以上の添字は節であり
        要素は節の親の添字を指す
        """
        self.table = [-1] * size
        self.size = [1] * size
        
    def find(self, x):
        """
        xを持つ素集合の根を返す
        """
        if self.table[x] < 0:
            # 根の場合
            return x
        else:
            # 節の場合: 経路圧縮(path compression)
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        """
        x, yを持つ素集合を併合(Union)する
        """
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:  # x,yが異なる素集合に含まれている場合のみ併合
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
if __name__=="__main__":
    N, M = map(int, input().split())
    Q = [list(map(int, input().split())) for _ in range(M)]
    u = UnionFind(N)
    unconv = N*(N-1)//2
    ans = []
    for q in reversed(Q):
        ans.append(unconv)
        a = u.find(q[0]-1)
        b = u.find(q[1]-1)
        if a!=b:
            unconv -= u.table[a]*u.table[b]
        u.union(q[0]-1, q[1]-1)
    for a in reversed(ans):
        print(a)
rgb = int(input().replace(" ",""))
     
    if rgb % 4 == 0:
      print("YES")
    else:
      print("NO")

### FIXED CODE ###

rgb = int(input().replace(" ",""))
     
if rgb % 4 == 0:
      print("YES")
else:
      print("NO")
n,k=map(int,input().split())
List=list(map(int,input().split()))


li = []

for i in range(n):
    count=0
    for j in range(n):
        if List[i]>List[j]:
            count += 1
    li.append(count)
print(str(sum(li))+"li")


count2=0

for i in range(1,n):
    for j in range(i+1,n+1):
        #print(i,j)
        if int(List[i-1]) > int(List[j-1]):
            count2 += 1
    #print(str(count2)+"count2")


for m in range(k-1,0,-1):
    counted=count2+count2*(m-1)




ans = counted % 1000000007
print(ans)

### FIXED CODE ###

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


li = []

for i in range(n):
    count=0
    for j in range(n):
        if List[i]>List[j]:
            count += 1
    li.append(count)

count2=0

for i in range(1,n):
    for j in range(i+1,n+1):
        if int(List[i-1]) > int(List[j-1]):
            count2 += 1

counted = k*count2 + (sum(li))*k*(k-1)//2

ans = counted % (10**9+7)
print(int(ans))
N= int(input())
s = []
for i in range(N):
    s.append(input())

M= int(input())
t = []
for i in range(M):
    t.append(input())

    
max_count = 0
for i in range(N):
    for j in range(M):
        B = s.count(s[i]) - t.count(s[i])
        C = s.count(t[i]) - t.count(t[i])
        
        if B > C:
            E = B
        else:
            E = C
               
        if E > max_count:
            max_count = E
    
print(max_count)


### FIXED CODE ###

A, B, C = list(map(int, input().split()))

if A + B >= C:
  print("Yes")
else:
  print("No")
h,w=map(int,input().split())
if h==1 ir w==1:
    print(1)
else:
    print((h*w)//2 if h%2==0 else ((h-1)*w)//2-(-w//2))

### FIXED CODE ###

h,w=map(int,input().split())
if h==1 or w==1:
    print(1)
else:
    print((h*w)//2 if h%2==0 else ((h-1)*w)//2-(-w//2))
import itertools

def fff(x):
    dp=[0]*k
    dp[0]=1
    for u in itertools.chain(a[:x],a[x+1:]):
        h=dp[:]
        for i in range(u,k):
            h[i]=h[i]|dp[i-u]
        dp=h
    cnt=0
    for i in range(k-a[x],k):
        cnt+=dp[i]
    if cnt==0:
        return True
    else:
        return False

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high-low>1:
    mid=(high+low)//2
    if fff(mid):    #不必要
        low=mid
    else:
        high=mid

if fff(high):
    print(high+1)
else:
    print(low+1)

### FIXED CODE ###

import itertools

def fff(x):
    dp=[0]*k
    dp[0]=1
    for u in itertools.chain(a[:x],a[x+1:]):
        h=dp[:]
        for i in range(u,k):
            h[i]=h[i]|dp[i-u]
        dp=h
    cnt=0
    for i in range(max(0,k-a[x]),k):
        cnt+=dp[i]
    if cnt==0:
        return True
    else:
        return False

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high-low>1:
    mid=(high+low)//2
    if fff(mid):    #不必要
        low=mid
    else:
        high=mid

if fff(high):
    print(high+1)
elif fff(low):
    print(low+1)
else:
    print(0)
# coding: utf-8
# Your code here!

import math 

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



for i in range(1,k+1):
    a = 1
    b = 1
    for j in range(1,i+1):
        a *= (n-k+2-j)/j
    for j in range(1,i):
        b *= (k-j)/j
    a = int(a)
    b = int(b)
    a %= 10**9+7
    b %= 10**9+7
    print(a*b%(10**9+7))


### FIXED CODE ###

# coding: utf-8
# Your code here!


from scipy.misc import comb
mod = 10**9 + 7

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

for i in range(1,k+1):
    a = int(comb(k-1, i-1, exact=True)) % mod
    b = int(comb(n-k+1, i, exact=True)) % mod 
    print(a*b%mod)
import sys
from fractions import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

a = [x >> 1 for x in a]

for i in range(n-1):
    a[i+1] = int(a[i] * a[i+1] / gcd(a[i], a[i+1]))

if a[n-1] > 10**9:
    print("0")
else:
    t = m // a[i+1]
    ans = (m // a[i+1]) - (m // (a[i+1] * 2))
    print(ans)


### FIXED CODE ###

from fractions import gcd
from functools import reduce

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M, *A = map(int, read().split())
 
# 「奇数倍」に帰着
A = [x >> 1 for x in A]
 

def merge(a, b):
    g = gcd(a, b)
    a //= g
    b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n


x = reduce(merge, A)

if x == 0:
    answer = 0
else:
    answer = (M//x) - (M//(x+x))
 
print(answer)
N,M,K = list(map(int,input().split()))

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
# print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
# print("KG:",KG)

def dfs(G,v):
    global l
    # nを訪問済みにする
    seen[v] = 1
    l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        else:
            dfs(G,next_v)

Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [0]*N
seen = [0]*N
Y = []
for v in range(N):
    l = 0
    seenV = []
    if seen[v] == 0:
        dfs(G,v)
    """
        print("dfs done !!!")
    print("v=",v+1,"seen:",seen)
    print("l=",l)
    print(seenV)
    """
    for sv in seenV:
        Adj_size[sv] = l
        Adj[sv] = seenV
    # print("Adj_size:",Adj_size)
    
    # 出力
    y = Adj_size[v] - len(G[v])-1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    # print("v=",v+1,"y=",y)
    Y.append(str(y))

"""
print("ADj",Adj)
print("Y",Y)
print("G",G)
"""
print(" ".join(Y))



### FIXED CODE ###

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
 
def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)
 
def size(x):
  return-par[find(x)]
 
N,M,K = map(int,input().split())
par=[-1]*N
B = [set() for _ in range(N)]
FF = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    FF[a-1] += 1
    FF[b-1] += 1
# print(F)
for j in range(K):
    a,b = map(int,input().split())
    B[a-1].add(b-1)
    B[b-1].add(a-1)

Y = []
for i in range(N):
    y = size(i) - FF[i] -1
    for b in B[i]:
        if same(i,b):
            y += -1
    Y.append(str(y))
print(" ".join(Y))
w,h,x,y = map(double, input().split())
if  w/2 = x and h/2 = y:
	ans = 1
else:
	ans = 0
print (w*h/2,ans)

### FIXED CODE ###

w,h,x,y = map(int, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)
r=float(input())
string=str(r**2*3.141592)+" "+str(2*3.141592*r)
print(string)

### FIXED CODE ###

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

string=str(a[0]//a[1])+" "+str(a[0]%a[1])+" "+str("%.10f"%(a[0]/a[1]))
print(string)
n, c = map(int, input().split())
data = [0 for j in range(10**5+1)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s] += 1
    data[t+1] -= 1
for i in range(10**5):
    data[i+1] += data[i]
print(max(data))

### FIXED CODE ###

n, c = map(int, input().split())
data = [[0 for i in range(c+1)] for j in range(10**5+2)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s][channel] += 1
    data[t+1][channel] -= 1
for i in range(c+1):
    for j in range(1,10**5+2):
        data[j][i] += data[j-1][i]
ans = 0
for i in range(10**5+2):
    sum_channel = 0
    for j in range(c+1):
        if data[i][j] == 1:
            sum_channel += 1
    ans = max(ans, sum_channel)
print(ans)
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=n-1
cnt=0
ans=0

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

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)
s = list(input())
k = int(input())

s += s[0]

cnt = 0
pre = s[0]
for i in range(1,len(s)):
    if s[i]==pre:
        cnt += 1
        pre =''
    else:
        pre = s[i]
ans = cnt*k
if (s[-3]!=s[-2]) and (s[-2]==s[-1]):
    print(ans-1)
else:
    print(ans)

### FIXED CODE ###

s = list(input())
k = int(input())
s += '+'

releki = []
cnt = 1
pre = s[0]
for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
        
ans = 0
for i in range(len(releki)):
    ans += releki[i][1]//2
if len(releki)==1:
    print((len(s)-1)*k//2)
    exit()
if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans)
import math

r = int(input())
print("{:.6f} {:.6f}\n".format(math.pi * r ** 2, 2 * math.pi * r))

### FIXED CODE ###

import math

r = float(input())
print("{:.6f} {:.6f}\n".format(math.pi * r ** 2, 2 * math.pi * r))
import networkx as nx
import matplotlib.pyplot as plt
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.single_target_shortest_path(g,target=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][1])

### FIXED CODE ###

import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])
from collections import deque
s = deque(list(input()))
cnt, i = 0, 0
l = len(s)

while i < l:
    if s[i] == s[i+1]:
        cnt += 1
        i += 2
    i += 1

print(l-cnt)

### FIXED CODE ###

s = list(input())
cnt, i = 0, 1
l = len(s)

while i < l:
    if s[i] == s[i-1]:
        cnt += 1
        i += 2
    i += 1

print(l-cnt)