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

import numpy as np
import sys

N, K = map(int, input().split())
K2 = K * 2
Mij = np.zeros((K2 + 1, K2 + 1), dtype=int)

def imos(i1, j1, i2, j2):
    Mij[i1][j1] += 1
    Mij[i1][j2] -= 1
    Mij[i2][j1] -= 1
    Mij[i2][j2] += 1

for _ in range(N):
    i, j, s = sys.stdin.readline().split()
    i = int(i) % K2
    j = int(j) % K2
    if s == "B":
        i = (i + K) % K2
    i1 = i % K
    j1 = j % K
    if (i < K and j < K) or (K <= i and K <= j):
        imos(0, 0, i1, j1)
        imos(0, j1 + K, i1, K2)
        imos(i1 + K, 0, K2, j1)
        imos(i1 + K, j1 + K, K2, K2)
        imos(i1, j1, i1 + K, j1 + K)
    else:
        imos(0, j1, i1, j1 + K)
        imos(i1 + K, j1, K2, j1 + K)
        imos(i1, 0, i1 + K, j1)
        imos(i1, j1 + K, i1 + K, K2)

# 累積和
Mij = np.cumsum(Mij, axis=0)
Mij = np.cumsum(Mij, axis=1)

print(Mij.max())

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
K2 = 2 * K
Mij = [[0 for _ in range(K2 + 1)] for _ in range(K2 + 1)]


def imos(x1, y1, x2, y2):
    Mij[y1][x1] += 1
    Mij[y2][x2] += 1
    Mij[y2][x1] -= 1
    Mij[y1][x2] -= 1

for _ in range(N):
    ls = input().split()
    x = int(ls[0]) % K2
    y = int(ls[1]) % K2
    if ls[2] == "B":
        y = (y + K) % K2
    x_ = x % K
    y_ = y % K

    if (x < K and y < K) or (K <= x and K <= y):
        imos(0, 0, x_ + 1, y_ + 1)
        imos(x_ + K + 1, 0, K2, y_ + 1)
        imos(0, y_ + K + 1, x_ + 1, K2)
        imos(x_ + K + 1, y_ + K + 1, K2, K2)
        imos(x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1)
    else:
        imos(x_ + 1, 0, x_ + K + 1, y_ + 1)
        imos(x_ + 1, y_ + K + 1, x_ + K + 1, K2)
        imos(0, y_ + 1, x_ + 1, y_ + K + 1)
        imos(x_ + K + 1, y_ + 1, K2, y_ + K + 1)

Mij = np.array(Mij)
for x in range(K2):
    Mij[:, x + 1] += Mij[:, x]
for y in range(K2):
    Mij[y + 1, :] += Mij[y, :]

print(Mij.max())
### BUGGY CODE ###

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

sum = 1

for i in range(a,b+1):
    sum *= i
    
if sum < 0:
    print("Negative")
elif sum == 0:
    print("Zero")
else:
    print("Positive")

### FIXED CODE ###

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

if a < 0 and b < 0:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")

elif a <= 0 and b >= 0:
    print("Zero")

else:
    print("Positive")
### BUGGY CODE ###

import numpy as np
S = input()
mod = 10 ** 9 + 7

n = len(S)
dp = np.zeros((n, 13))
a = S[-1]
now, pre = 10, 1
x_ = dp[0]
l = [1, 10, 9, 12, 3, 4]
l = [[i * l_ % 13 for i in range(1, 10)] for l_ in l]
li = 1
if a == "?":
    x_[0:10] = 1
else:
    x_[int(a)] = 1
for s, x in zip(S[-2::-1], dp[1:]):
    if s == "?":
        x += x_
        for v in l[li]:
            x %= mod
            x[v:] += x_[:-v]
            x[:v] += x_[-v:]
    else:
        if s == "0":
            x += x_
        else:
            v = l[li][int(s) - 1]
            x[v:] += x_[:-v]
            x[:v] += x_[-v:]
    x %= mod
    li += 1
    li %= 6
    x_ = x
print(int(dp[-1][5]))

### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

#!usr/bin/env python3


import sys


def I(): return int(sys.stdin.readline())


def solve():
    n = I()
    sli = [input() for i in range(n)]
    setli = set(sli)
    rank = {}
    for i in setli:
        j = sli.count(i)
        rank[i] = j
    for i in sorted([k for k, v in rank.items() if v == max(rank.values())]):
        print(i)


# Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    sli = [input() for i in range(n)]
    rank = defaultdict(lambda: 0)
    for i in sli:
        rank[i] += 1
    rank = list(rank.items())
    rank.sort(key=lambda x: (-x[1], x[0]))
    for i, j in rank:
        if j == rank[0][1]:
            print(i)


# Solve
if __name__ == "__main__":
    solve()
### BUGGY CODE ###

N = int(input())
mod = 10**9 + 7
power = 1
for i in range(1, N+1):
    power *= i
print(power%mod)


### FIXED CODE ###

N = int(input())
mod = 10**9 + 7
power = 1
for i in range(1, N+1):
    power *= i
    power %= mod
print(power)
### BUGGY CODE ###

n=input()
x=1
for i in map(int,input().split()):
  x*=i
if x>10**18:
  print(-1) 
else:
  print(x)

### FIXED CODE ###

input()
x=1
l=sorted(map(int,input().split()))
for i in l:
  if i==0:
    print(0)
    break
  x*=i
  if x>10**18:
    print(-1)
    break
else:
  if x>10**18:
    print(-1)
  else:
    print(x)
### BUGGY CODE ###

from collections import defaultdict

def main():
    s = input()
    n = len(s)
    d = defaultdict(int)
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        d[num % 2019] += 1

    ans = 0
    for _, cnt in d.items():
        ans += cnt * (cnt - 1) // 2
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import bisect
from itertools import permutations
A, B, Q = map(int, input().split())
S = []
for _ in range(A):
    S.append(int(input()))
T = []
for _ in range(B):
    T.append(int(input()))

for _ in range(Q):
    x = int(input())
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    none_flag = [False, False]
    c = []
    d = []
    if sr == A:
        sr = None
        sl = A-1
        none_flag[0] = True
        c.append([S[sl], 0])
        d.append(S[sl])
    elif sr == 0:
        sl = None
        none_flag[0] = True
        c.append([S[sr], 0])
        d.append(S[sr])
    else:
        sl = sr-1
        c.append([S[sr], 0])
        c.append([S[sl], 0])
        d.append(S[sl])
        d.append(S[sr])
    if tr == B:
        tr = None
        none_flag[1] = True
        tl = B-1
        c.append([T[tl], 1])
        d.append(T[tl])
    elif tr == 0:
        tl = None
        none_flag[1] = True
        c.append([T[tr], 1])
        d.append(T[tr])
    else:
        tl = tr-1
        c.append([T[tr], 1])
        c.append([T[tl], 1])
        d.append(T[tr])
        d.append(T[tl])
    c.sort()
    ans = 10**16
    for elem in permutations(c):
        tmp = 0
        flag = [False, False]
        now_pos = x
        flag_calc = True
        for pos, kind in elem:
            if flag[kind]:
                flag_calc = False
                break
            tmp += abs(pos-now_pos)
            now_pos = pos
            flag[kind] = True
            if flag[0] and flag[1]:
                break
        if flag_calc:
            ans = min(ans, tmp)
    print(ans)


### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
S = []
for _ in range(A):
    S.append(int(input()))
T = []
for _ in range(B):
    T.append(int(input()))

for _ in range(Q):
    x = int(input())
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    tmpS = []
    tmpT = []
    if sr == A:
        tmpS.append(S[A-1])
    elif sr == 0:
        tmpS.append(S[sr])
    else:
        tmpS.append(S[sr])
        tmpS.append(S[sr-1])
    if tr == B:
        tmpT.append(T[B-1])
    elif tr == 0:
        tmpT.append(T[tr])
    else:
        tmpT.append(T[tr])
        tmpT.append(T[tr-1])
    ans = 10**16
    for s in tmpS:
        tmp = abs(x-s)
        tmp1 = 10**16
        for elemT in tmpT:
            tmp1 = min(tmp1, abs(elemT-s))
        ans = min(ans, tmp+tmp1)
    for t in tmpT:
        tmp = abs(x-t)
        tmp1 = 10**16
        for elemS in tmpS:
            tmp1 = min(tmp1, abs(elemS-t))
        ans = min(ans, tmp+tmp1)
    print(ans)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    q = int(input())
    l = []
    b = 0
    count = 0
    for i in range(q):
        a = list(map(int,input().split()))
        if a[0] == 1:
            l.append(a[1])
            count += 1
            b += a[2]
        else:
            l.sort()
            if count %2 == 0:
                ans = sum(l[(count-1)//2+1:])-sum(l[:(count-1)//2+1])
                print(l[(count-1)//2],ans+b)
            else:
                ans = sum(l[(count-1)//2+1:])-sum(l[:(count-1)//2])
                print(l[(count-1)//2],ans+b)
if __name__ == "__main__":
    main()       

### FIXED CODE ###

import heapq

q = int(input())
l = []
r = []
ans = 0

for i in range(q):
    a = list(map(int,input().split()))
    if a[0] == 1:
        ans += a[2]
        if l == []:
            heapq.heappush(r,a[1])
            heapq.heappush(l,-a[1])
        else: 
            ll = -heapq.heappop(l)
            rr = heapq.heappop(r)
            if ll <= a[1] <= rr:
                heapq.heappush(r,rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(l,-a[1]) 

            elif ll > a[1]:
                ans += ll-a[1]
                heapq.heappush(r,rr)
                heapq.heappush(r,ll) 
                heapq.heappush(l,-a[1])
                heapq.heappush(l,-a[1]) 
            else:
                ans += a[1] -rr
                heapq.heappush(l,-rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(r,a[1]) 
        
    else:
        a = heapq.heappop(l)
        print(-a,ans)
        heapq.heappush(l,a)
### BUGGY CODE ###

T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    a, b, c, d = r[0], r[1], r[2], r[3]
    s = a


    s_list = []
    while True:
        s_list.append(s)


        if s > 100:
            s -= b*((s//b)-1)
            while s <= c:
                s+= c
        s -= b
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


        if s <0:
            print('No')
            break
        if s != s_list[-1]:
            if s in s_list:
                print('Yes')
                break

        if s <= c:
            s += d
            s_list.append(s)
            if s != s_list[-1]:
                if s in s_list:
                    print('Yes')
                    break


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)

DP=[1<<60]*N
DP[N-1]=0

for i in range(N-2,-1,-1):
    score=0
    for x in E[i]:
        score+=1+DP[x]

    DP[i]=score/len(E[i])
        
ANS=DP[0]

for i in range(N-2):
    rem=-1
    remsc=0
    for j in E[i]:
        if DP[j]>remsc:
            rem=j
            remsc=DP[j]

    if remsc==0:
        continue

    E[i].remove(rem)

    NDP=[1<<60]*N
    NDP[N-1]=0

    for l in range(N-2,-1,-1):
        
        score=0
        
        if len(E[l])==0:
            continue
        
        for x in E[l]:
            score+=1+NDP[x]

        NDP[l]=score/len(E[l])

    #print(i,rem,E,NDP)

    ANS=min(ANS,NDP[0])
    E[i].add(rem)

print(ANS)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)

DP=[M]*N
DP[N-1]=0

for i in range(N-2,-1,-1):
    score=0
    for x in E[i]:
        score+=1+DP[x]

    DP[i]=score/len(E[i])
        
ANS=DP[0]

for i in range(N-2):
    rem=-1
    remsc=0
    for j in E[i]:
        if DP[j]>remsc:
            rem=j
            remsc=DP[j]

    if remsc==0:
        continue

    E[i].remove(rem)

    NDP=[M]*N
    NDP[N-1]=0

    for l in range(N-2,-1,-1):
        
        score=0
        
        if len(E[l])==0:
            continue
        
        for x in E[l]:
            score+=1+NDP[x]

        NDP[l]=score/len(E[l])

    #print(i,rem,E,NDP)

    ANS=min(ANS,NDP[0])
    E[i].add(rem)

print(ANS)
### BUGGY CODE ###

S = str(input())
s = S
res = True
while res == True:
    s = s.replace('01','')
    s = s.replace('10','')
    res0 = s.find('01')
    res1 = s.find('10')
    if res0 == -1 and res1 == -1:
        res = False
print(len(S) - len(s))

### FIXED CODE ###

S = str(input())
s = S
cont0 = s.count('0')
cont1 = s.count('1')
if cont0 > cont1:
    print(cont1 * 2)
else:
    print(cont0 * 2)
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
count=0
new=[]
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
for i in range(0,len(l)):
    if l[i]>2*10**5:
        pass
    else:
        new.append((l[i],i+1))

new.sort()
for i in range(0,len(new)):
    for j in range(i+1,len(new)):
        if new[i][0]+new[j][0]>2*10**5:
            break
        if diff(new[i][1],new[j][1])==new[i][0]+new[j][0]:
            count+=1
print(count)




### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
count=0
new=[]
s=set()
d={}
for i in range(0,len(l)):
    new.append(i+1-l[i])
    s.add(i+1+l[i])
    if i+1+l[i] in d.keys():
        d[i+1+l[i]]+=1
    else:
        d[i+1+l[i]]=1
for i in range(0,len(new)):
    if new[i] in s:
        count+=d[new[i]]
print(count)
### BUGGY CODE ###

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
dp = [[[0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(C[3]+1):
    for j in range(C[3]+C[2]+1-k):
        for i in range(N+1-j-k):
            if i + j + k == 0:
                continue
            res = N
            if i > 0:
                res += i * dp[i-1][j][k]
            if j > 0:
                res += j * dp[i+1][j-1][k]
            if k > 0:
                res += k * dp[i][j+1][k-1]
            dp[i][j][k] = res / (i + j + k)
 
print(dp[C[1]][C[2]][C[3]])

### FIXED CODE ###


N = int(input())
A = list(map(int, input().split()))
C = [0, A.count(1), A.count(2), A.count(3)]
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(C[3]+1):
    for j in range(C[3]+C[2]+1-k):
        for i in range(N+1-j-k):
            if i + j + k == 0:
                continue
            res = N
            if i > 0:
                res += i * dp[i-1][j][k]
            if j > 0:
                res += j * dp[i+1][j-1][k]
            if k > 0:
                res += k * dp[i][j+1][k-1]
            dp[i][j][k] = res / (i + j + k)
 
print(dp[C[1]][C[2]][C[3]])
### BUGGY CODE ###

n, p = [int(i) for i in input().split()]
max_x = int(p**(1/n))+1
ans = 1
for i in range(max_x, 1, -1):
    if p % (i**n) == 0:
        ans = i
        break
print(ans)

### FIXED CODE ###

n, p = [int(i) for i in input().split()]
tmp = p**(1/n)
if tmp - int(tmp) > 0.999:
    max_x = int(tmp) + 1
else:
    max_x = int(tmp)
ans = 1
for i in range(max_x, 1, -1):
    if p % pow(i,n) == 0:
        ans = i
        break
print(ans)
### BUGGY CODE ###

n = int(input())

table = [0]*(n+1)
for i in range(1,n+1):
   for j in range(i,n+1,i):
      table[j] += 1
ans = 0
for i in range(1,n+1):
  ans += i*table[i]
print(ans)

### FIXED CODE ###

n = int(input())

ans = 0
for i in range(1,n+1):
  k = n//i
  ans += i*(k*(k+1)//2)
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
while all(aa%2==0 for aa in a):
  ans+=1
  for aa in a:
    aa=aa//2
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
while all(aa%2==0 for aa in a):
  ans+=1
  a=[aa//2 for aa in a]
print(ans)
### BUGGY CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

def solve(i,m):
  if m == 0:
    return True
  if i >= n:
    return False
  res = solve(i+1,m) or solve(i+1, m - A[i])
  return res

for m in M:
    if solve(0, m):
      print 'yes'
    else:
      print 'no'

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

min = min(A)
sum = sum(A)

def solve(i,m):
  if sum < m:
    return False
  if m == 0:
    return True
  if i >= n:
    return False
  res = solve(i+1,m) or solve(i+1, m - A[i])
  return res
 
for m in M:
    if solve(0, m):
      print 'yes'
    else:
      print 'no'
### BUGGY CODE ###

import itertools
L,R = list(map(int,input().split()))
N_list = [i for i in range(L,R+1)]
P = itertools.combinations(N_list,2)
P = list(P)
ans = L*(L+1)%2019
for p in P[1:]:
    ans = min(ans,p[0]*p[1]%2019)
print(ans)

### FIXED CODE ###

import itertools
L,R = list(map(int,input().split()))
if R-L >= 2020:
  print(0)
  exit()
N_list = [i for i in range(L,R+1)]
P = itertools.combinations(N_list,2)
P = list(P)
ans = L*(L+1)%2019
for p in P[1:]:
    ans = min(ans,p[0]*p[1]%2019)
print(ans)
### BUGGY CODE ###

import math
Q = int(input())
lr = [list(map(int, input().split())) for i in range(Q)]

max_l = max(lr, key=lambda x:x[1])[1]

a = list(range(2,int(math.ceil(max_l**0.5)+1)))

m = 1
while True:
    b = filter(lambda x: x%a[m-1] != 0,a[m:])
    a = a[:m]
    a.extend(b)
    m += 1
    if m > len(a):
        break

like2017 = [3]
for i in range(5,max_l+1,4):
    for j in a:
        if not ((i % j != 0 or i in a) and ((i+1)/2 % j != 0 or (i+1)/2 in a)):
            break
        if j == a[-1]:
            like2017.append(i)

for i in range(Q):
    print(len(list(filter(lambda x: lr[i][0] <= x <= lr[i][1],like2017))))


### FIXED CODE ###

import math
Q = int(input())
lr = [list(map(int, input().split())) for i in range(Q)]

max_l = max(lr, key=lambda x:x[1])[1]

prime = list(range(2,int(math.ceil(max_l**0.5)+1)))

m = 1
while True:
    b = filter(lambda x: x%prime[m-1] != 0,prime[m:])
    prime = prime[:m]
    prime.extend(b)
    m += 1
    if m > len(prime):
        break

like2017 = {-1:0,1:0}
for i in range(3,max_l+2,2):
    k = 0
    for j in prime:
        if (i%j == 0 or ((i+1)/2)%j == 0) and i != j and (i+1)/2 != j:
            k += 1
            break
    if k == 0:
        like2017[i] = like2017[i-2] + 1
    else:
        like2017[i] = like2017[i-2]


for i in range(Q):
    print(like2017[lr[i][1]]-like2017[lr[i][0]-2])
### BUGGY CODE ###

n=int(input())
if n%2==1:
  a=2
  b=n//2+1
  c=n+2
else:
  a=1
  b=n//2
  c=n+1
ans=1
for s in range(a,b+1):
  ans*=s*(c-s)
print(ans%(10**9+7))

### FIXED CODE ###

from math import factorial;print(factorial(int(input()))%(10**9+7))
### BUGGY CODE ###

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for i, (ai, bi) in enumerate(ab):
    graph[ai - 1].append(bi)
    graph[bi - 1].append(ai)

# print("#", graph)

cnttab = [0] * N
for j, (pj, xj) in enumerate(px):
    cnttab[pj - 1] += xj

# print("#", cnttab)


ans = [None] * N
ans[0] = cnttab[0]
# from collections import deque
# q = deque([(1, None, ans[0])])

def mypopleft(q, idx):
    return q[idx], (idx + 1)

q = [(1, None, ans[0])]
idx = 0
while len(q) > idx:
    (src, prev, score), idx = mypopleft(q, idx)
    for dst in graph[src - 1]:
        if dst == prev: continue
        ans[dst - 1] = score + cnttab[dst - 1]
        if len(graph[dst - 1]) > 1:
            q.append((dst, src, ans[dst - 1]))

print(' '.join(map(str, ans)))

### FIXED CODE ###

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

parent = [None] * N
parent[0] = 0

score = [0] * N
for pi, xi in px:
    score[pi - 1] += xi

ans = [None] * N

from collections import deque

q = deque([(0, 0)])
while len(q) > 0:
    src, score_tmp = q.popleft()
    score_tmp += score[src]
    ans[src] = score_tmp
    for dst in graph[src]:
        if ans[dst] != None: continue
        q.append((dst, score_tmp))

print(' '.join(map(str, ans)))
### BUGGY CODE ###

N = int(input())
s = []
count=0

def duplicates(list):
  seen=[]
  return [x for x in s if x not in seen and not seen.append(x)]

for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

duplicate_list = duplicates(s)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

### FIXED CODE ###

from collections import defaultdict

N = int(input())
s = defaultdict(lambda:0)
count=0

for i in range(N):
  a = "".join(sorted(input()))
  s[a] +=1
  
  if s[a] >1:
    count += s[a]-1
print(count)
### BUGGY CODE ###

S = input()
l = len(S)
#table = str.maketrans({'01':'','10':''})
while True:
  S_ = S.replace('01','').replace('10','')
  if S_ != S:
  	S = S_
  else:
    break
print(l-len(S))

### FIXED CODE ###

S = input()
print(min(S.count('0'),S.count('1'))*2)
### BUGGY CODE ###

n,m = map(int,input().split())
a =  [int(n) for n in input().split()]
b = [i + j for i in a for j in a ]
b.sort(reverse=True)
print(sum(b[:m]))

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    A = LI()
    a = sorted(A,reverse=True)

    high = a[0] * 2
    low = 0
    while high > low + 1:
        mid = (high + low) // 2

        cnt = 0
        j = N - 1
        for i in range(N):
            while a[i] + a[j] < mid:
                j -= 1
                if j < 0: break
            else:
                cnt += (j+1)
                continue
            break
        if cnt <= M:
            high = mid
        else:
            low = mid

    s = [a[0]]
    for i in range(1,N):
        s.append(s[-1]+a[i])

    ans = 0
    cnt = 0
    m = a[0] * 2
    j = N - 1
    for i in range(N):
        while a[i] + a[j] < low:
            j -= 1
            if j < 0: break
        else:
            ans += a[i] * (j+1) + s[j]
            cnt += j + 1
            m = min(m,a[i] + a[j])
            continue
        break

    print(ans - (cnt-M) * m)


if __name__ == '__main__':
    main()