Harryxun/stf_run huggingface dataset:
from collections import Counter
s = input()
t = input()
s_cnt = sorted(Counter(s).most_common())
t_cnt = sorted(Counter(t).most_common())[::-1]
s_replaced = ""
t_replaced = ""
for k, v in s_cnt:
    s_replaced += k * v 
for k, v in t_cnt:
    t_replaced += k * v 

def judge(s, t):
    for i in range(len(s)):
        if ord(s[i]) > ord(t[i]):
            return False
        if ord(s[i]) < ord(t[i]):
            return True
    if len(s) < len(t):
        return True
    else:
        return False

if judge(s_replaced, t_replaced):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from collections import Counter
s = input()
t = input()
s_cnt = sorted(Counter(s).most_common())
t_cnt = sorted(Counter(t).most_common())[::-1]
s_replaced = ""
t_replaced = ""
for k, v in s_cnt:
    s_replaced += k * v 
for k, v in t_cnt:
    t_replaced += k * v 

def judge(s, t):
    for i in range(min(len(s), len(t))):
        if ord(s[i]) > ord(t[i]):
            return False
        if ord(s[i]) < ord(t[i]):
            return True
    if len(s) < len(t):
        return True
    else:
        return False

if judge(s_replaced, t_replaced):
    print("Yes")
else:
    print("No")
import math

A, B, C, D = input().split()

T_hp = int(A)
T_atk = int(B)
A_hp = int(C)
A_atk = int(D)

T_burstturn = math.ceil(T_hp / A_atk)
A_burstturn = math.ceil(A_hp / T_atk)

if T_burstturn < A_burstturn:
    print("No")
else:
    prit("Yes")
    

### FIXED CODE ###

import math

A, B, C, D = input().split()

T_hp = int(A)
T_atk = int(B)
A_hp = int(C)
A_atk = int(D)

T_burstturn = math.ceil(T_hp / A_atk)
A_burstturn = math.ceil(A_hp / T_atk)

if T_burstturn < A_burstturn:
    print("No")
else:
    print("Yes")
s = list(input())
f = s[0]
e = s[-1]
s.pop(0).pop(-1)
l = len(s)
print("".join([f, str(l), e]))

### FIXED CODE ###

s = list(input())
f = s[0]
e = s[-1]
s.pop(0)
s.pop(-1)
l = len(s)
print("".join([f, str(l), e]))
def main():
        N = int(input())
        X = []
        L = []
        for i in range(N):
            x, l = [int(s) for s in input().split()]
            X.append(x)
            L.append(l)
     
        ranges = []
        for i in range(N):
            ranges.append((X[i] - L[i], X[i] + L[i]))
        ranges.sort(key=lambda x: x[0])
     
        while True:
            dup = [0 for i in range(len(ranges))]
            for i in range(len(ranges) - 1):
                if ranges[i][1] > ranges[i + 1][0]:
                    dup[i] += 1
                    dup[i + 1] += 1
     
            remove_index = [(i, dup[i]) for i in range(len(dup))]
            remove_index.sort(key=lambda x: x[1], reverse=True)
            if remove_index[0][1] == 0:
                break
            ranges.pop(remove_index[0][0])
        print(len(ranges))
     
     
    if __name__ == "__main__":
        main()

### FIXED CODE ###

def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[1])

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
        else:
            end = ranges[i][1]
    print(cnt)


if __name__ == "__main__":
    main()
n,s= map(int,input().split())
print(max(n+s,n-s,n*s)

### FIXED CODE ###

n,s= map(int,input().split())
print(max(n+s,n-s,n*s))
def Cubic(x):
    return x*x*x

if __name__ == '__main__':
    Cubic()

### FIXED CODE ###

print(int(input()) ** 3)
import math
n = int(input())
lis = [[0] * n for i in range(n)]
for i in range(n):
  for j in range(n):
    lis[i][j] = math.gcd(i+1,j+1)
ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += lis[i][lis[k][j]]
print(ans)

### FIXED CODE ###

import math
n = int(input())
lis = [[0] * n for i in range(n)]
for i in range(n):
  for j in range(n):
    lis[i][j] = math.gcd(i+1,j+1)
ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += lis[i][lis[k][j]-1]
print(ans)
r = (double)input().split()
import math
d = r * r * math.pi
l = 2 * r * math.pi
print("%f %f" %(d,l))

### FIXED CODE ###

r = float(input())
import math
d = r * r * math.pi
l = 2 * r * math.pi
print("%f %f" %(d,l))
S=str(input())
T=str(input())
ls = []
cnt = 0
if T in S:
    print(0)
else:
    for i in range(len(S)-len(T)):
        for j in range(len(T)):
            if T[j] != S[j+i]:
                #print (T[j],S[j+i])
                cnt += 1
        ls.append(cnt)
        cnt = 0
#print(ls)
print(min(ls))


### FIXED CODE ###

S=str(input())
T=str(input())
ls = []
cnt = 0
for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        #print(i,j)
        if T[j] != S[j+i]:
            #print(T[j],S[j+i])
            cnt += 1
    ls.append(cnt)
#print(ls)
print(min(ls))
import sys

N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[(1+p)/2 for p in P]
temp=sum(Q[:K])
ans=temp
for i in range(N-3):
  temp=temp-Q[i]+Q[i+K]
  ans=max(ans,temp)
else:
  print(ans)

### FIXED CODE ###

import sys

N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[(1+p)/2 for p in P]
temp=sum(Q[:K])
ans=temp
for i in range(N):
  try:
    temp=temp-Q[i]+Q[i+K]
    ans=max(ans,temp)
  except:
    pass
else:
  print(ans)
from bisect import bisect_left
import sys
input = sys.stdin.readline

N = int(input())
X = [0] * N
Y = [0] * N
U = [''] * N
for i in range(N):
    x, y, u = input().split()
    X[i] = int(x)
    Y[i] = int(y)
    U[i] = u

def calc(X, Y, U):
    mx = min(X)
    for i in range(N):
        X[i] -= mx
    my = min(Y)
    for i in range(N):
        Y[i] -= my
    Mx = max(X)
    My = max(Y)
    up = [[] for _ in range(Mx+1)]
    down = [[] for _ in range(Mx+1)]
    left = [[] for _ in range(My+1)]
    right = [[] for _ in range(My+1)]
    for x, y, u in zip(X, Y, U):
        if u == 'U':
            up[x].append(y)
        if u == 'D':
            down[x].append(y)
        if u == 'L':
            left[y].append(x)
        if u == 'R':
            right[y].append(x)
    ret = float('inf')
    for x in range(Mx+1):
        up[x].sort()
        down[x].sort()
        s = t = 0
        while s < len(up[x]):
            while t < len(down[x]) and up[x][s] > down[x][t]:
                t += 1
            if t < len(down[x]):
                ret = min(ret, (down[x][t] - up[x][t]) * 5)
            s += 1
    for y in range(My+1):
        right[y].sort()
        left[y].sort()
        s = t = 0
        while s < len(right[y]):
            while t < len(left[y]) and right[y][s] > left[y][t]:
                t += 1
            if t < len(left[y]):
                ret = min(ret, (left[y][t] - right[y][t]) * 5)
            s += 1
    return ret


ans = calc(X, Y, U)
nX = [X[i] - Y[i] for i in range(N)]
nY = [X[i] + Y[i] for i in range(N)]

U1 = []
for u in U:
    if u == 'R':
        U1.append('U')
    elif u == 'L':
        U1.append('D')
    else:
        U1.append(u)
ans = min(ans, calc(nX, nY, U1))

U2 = []
for u in U:
    if u == 'U':
        U2.append('L')
    elif u == 'D':
        U2.append('R')
    else:
        U2.append(u)
ans = min(ans, calc(nX, nY, U2))

print(ans if ans < float('inf') else 'SAFE')

### FIXED CODE ###

import sys
input = sys.stdin.readline

INF = 10**18

N = int(input())
X = [0] * N
Y = [0] * N
U = [''] * N
for i in range(N):
    x, y, u = input().split()
    X[i] = int(x)
    Y[i] = int(y)
    U[i] = u
M = 200000

def rotate():
    s = 'ULDR'
    for i in range(N):
        X[i], Y[i] = M - Y[i], X[i]
        U[i] = s[(s.index(U[i]) + 1) % 4]

def calc1():
    v = [[] for _ in range(M+1)]
    for x, y, u in zip(X, Y, U):
        if u in 'RL':
            v[y].append((x, u))
    ret = INF
    for y in range(M+1):
        v[y].sort(key=lambda p: p[0])
        for i in range(len(v[y])-1):
            if v[y][i][1] == 'R' and v[y][i+1][1] == 'L':
                ret = min(ret, (v[y][i+1][0] - v[y][i][0]) * 5)
    return ret

def calc2():
    v = [[] for _ in range(2*M+1)]
    for x, y, u in zip(X, Y, U):
        if u in 'UR':
            v[x+y].append((x, u))
    ret = INF
    for xy in range(2*M+1):
        v[xy].sort(key=lambda p: p[0])
        for i in range(len(v[xy])-1):
            if v[xy][i][1] == 'R' and v[xy][i+1][1] == 'U':
                ret = min(ret, (v[xy][i+1][0] - v[xy][i][0]) * 10)
    return ret

ans = INF
for i in range(4):
    ans = min(ans, calc1(), calc2())
    rotate()
print(ans if ans < INF else 'SAFE')
n = int(input())
a = list(map(int, input().split()))
count = 0

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

### FIXED CODE ###

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

while all(i % 2 == 0 for i in a):
    a = [j/2 for j in a]
    count += 1
print(count)
def comb(x,y):
    if y==1:
        return x
    elif y==2:
        return max(x*(x-1)//2, 0)
    elif y==3:
        return max(x*(x-1)*(x-2)//6, 0)


n = int(input())
k = int(input())
digit = len(str(n))

ans1 = comb(digit-1, k) * (9**k)

lst = [int(i) for i in list(str(n))]
if k==1:
    ans2 = lst[0]
elif k==2:
    ans2 = 0
    ans2 += (lst[0]-1) * (digit-1) * 9
    ans2 += lst[1] + (digit-2)*9
elif k==3:
    ans2 = 0
    ans2 += (lst[0]-1) * comb(digit-1, 2) * (9**2)
    ans2 += lst[1]*(digit-2)*9 + comb(digit-2, 2)*(9**2)
    
print(ans1+ans2)

### FIXED CODE ###

n = input()
k = int(input())

# dp[i桁まで][非0個数][未満フラグ]
dp = [[[0]*2 for _ in range(k+1)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(len(n)):
    x = int(n[i])
    for j in range(k):
        dp[i+1][j+1][1] += dp[i][j][1]*9
        dp[i+1][j][1] += dp[i][j][1]
        if x>0:
            dp[i+1][j][1] += dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][0]*(x-1)
            dp[i+1][j+1][0] += dp[i][j][0]
        else:
            dp[i+1][j][0] += dp[i][j][0]
    dp[i+1][k][1] += dp[i][k][1]
    dp[i+1][k][x>0] += dp[i][k][0]

print(sum(dp[len(n)][k]))
N = int(input())
H = list(map(int, input().split()))
 
ans = 1
if (N == 2) & (H[0] - H[1] >= 2):
    print('No')
    ans = -1
else:
    for i in range(1, N-1, 1):
        #print((H[i] - H[i+1]))
        if ((H[i-1] - H[i]) >= 1) & ((H[i] - H[i+1]) >= 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) == 0) & ((H[i] - H[i+1]) == 1):
            print('No')
            ans = -1
            break
        elif ((H[i-1] - H[i]) >= 2) or ((H[i] - H[i+1]) >= 2):
            print('No')
            ans = -1
            break
        else:
            continue

 
if (ans == 1): print('Yes')

### FIXED CODE ###

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

ans = 1
for i in reversed(range(1, N, 1)):
    if (H[i-1] - H[i]) == 1:
        H[i-1] -= 1
    if (H[i-1] - H[i]) > 1:
        print('No')
        ans = -1
        break
if ans == 1: print('Yes')
N = int(input())

A = [int(x) for x in input().split()]
A = sorted(A)


if A[0] == A[1]:
    cnt = 0
else:
    cnt = 1
    
for i in range(1,N):
    flag = True
    for j in range(i):
        if A[i]%A[j] == 0:
            flag = False
    if i != N-1:
        if A[i] == A[i+1]:
            flag = False
    
    if flag == True:
        cnt += 1
print(cnt)

### FIXED CODE ###

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

l=[0]*(10**6+1)
ans=0
#print(l)
for i in a:
    if l[i]==0:
        for j in range(i,10**6+1,i):
            l[j] += 1
    else:
        l[i] += 1
#print(l)
for i in a:
    if l[i]==1:
        ans+=1

print(ans)
l,r=map(int,input().split())
print(l,r)
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break

print(count)


### FIXED CODE ###

l,r=map(int,input().split())
count=2019
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(count)
N,A,B,C,D=map(int,input().split())
S=input()
if "##" in:
    print("No")
elif (S[C-2])=="#" and C>D:
    print("No")
elif (S[C])=="#" and C>D:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

N,A,B,C,D=map(int,input().split())
S=input()

if "##" in S[A:C-1] or "##" in S[B:D-1]:
    print("No")
    exit()
elif C>D and "..." not in S[B-2:D+1]:
    print("No")
else:
    print("Yes")
A,B=map(int,input())
A=A*B
print(int(A))


### FIXED CODE ###

A,B=map(int,input().split())
A=A*B
print(int(A))
from collections import defaultdict

N, Q = map(int,input().split())
s = [_ for _ in input()]
td = [[_ for _ in input().split()] for _ in range(Q)]
GOL = [1 for _ in range(N)]

listS = defaultdict(list)
for i, word in enumerate(s):
    listS[word[0]].append(i)

for t, d in td:
    dictS = listS.get(t)
    if dictS == None:
        continue
    for idx in dictS:
        if (idx == 0 and d == "L") or (idx == N - 1 and d == "R"):
            pass
        else:
            if d == "L":
                GOL[idx - 1] += GOL[idx]
            else:
                GOL[idx + 1] += GOL[idx]

        GOL[idx] = 0

print(sum(GOL))

### FIXED CODE ###


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

if A == B == C:
    print("Yes")
else:
    print("No")
x,a,b=list(int,input().split())
c=x-a
print(c%b)

### FIXED CODE ###

x,a,b=[int(input()) for i in range(3)]
c=x-a
print(c%b)
n=int(input())
h=list(map(int,input().split()))
cnt=0
ls=[]
i=0
while len(h)!=1:
    if h[i]>=h[i+1]:
        cnt+=1
        i+=1
        if i==len(h)-1:
          ls.append(cnt)
          cnt=0
          h.pop(0)
          i=0
          
    else:
        ls.append(cnt)
        cnt=0
        h.pop(0)
        i=0
print(max(ls))

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
cnt=0
ls=[0]*n
for i in range(n-1):
    if h[i]>=h[i+1]:
        cnt+=1
    else:
        ls[i]=cnt
        cnt=0
ls[-1]=cnt
print(max(ls))
import math
import numpy as np
def get_price(a,b,n):
    return a * n + b * int (math.log10(n) + 1)    
a, b, x = map(int,input().split(' '))
currnt_max = 0
price_range = [get_price(a,b,10 ** i) for i in range(0,10)]    
price_range = np.asarray(price_range)

start = price_range[price_range < x].argmax()
end = 10 ** (start + 1)
start = 10 ** start
if start == 10 ** 9:
    print(10 ** 9)
    exit()

for i in range(start,10**9 + 1):
    tmp = get_price(a,b,i)
    if tmp < x:
        currnt_max = i
    else:
        break
print(currnt_max)

### FIXED CODE ###

s = input()
day = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1 }
print(day[s])
import numpy as np
 
tmp =list(map(int, input().split()))
num=list(map(int, input().split()))
 
a[a>int(tmp[0]//2)]=a[a>int(tmp[0]//2)]-int(tmp[0]//2)
print(sum(a))

### FIXED CODE ###

import numpy as np
 
tmp =list(map(int, input().split()))
num=list(map(int, input().split()))

num.append(num[0]+tmp[0])

print(np.diff(num).sum()-np.diff(num).max())
#encoding=utf-8

inp = input()
x = 100000
for i in xrange(inp):
	x = x * 1.05
	if int(x % 1000) != 0:
		x += 1000 - int(x % 1000)

print int(x)

### FIXED CODE ###

#encoding=utf-8

inp = input()
x = 100000
for i in xrange(inp):
	x = x * 1.05
	if int(x % 1000) != 0:
		x += 1000 - int(x % 1000)

print int(x)
n = input()
nl = [int(i) for i in n]
nl_s = 0
for i in nl:
  nl_s += i
print("Yes" if n % nl_s == 0 else "No")

### FIXED CODE ###

n = input()
nl = [int(i) for i in n]
nl_s = 0
for i in nl:
  nl_s += i
print("Yes" if int(n) % nl_s == 0 else "No")
import sys
n = int(input())
w = []
for i in range(n):
    w.append(input())
if len(w) != len(set(w)):
    print("No")
    sys.exit()
for i in range(n-1):
    if w[i][len(w[i]) - 1] != w[i+1][len(w[i+1] - 1)]:
        print("No")
        sys.exit()
print("Yes")

### FIXED CODE ###

import sys
n = int(input())
w = []
for i in range(n):
    w.append(input())
if len(w) != len(set(w)):
    print("No")
    sys.exit()
for i in range(n-1):
    if w[i][len(w[i]) - 1] != w[i+1][0]:
        print("No")
        sys.exit()
print("Yes")
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
# 最小公倍数
# def gcd(a, b):
#     if a < b:
#         a, b = b, a
#     while a % b != 0:
#         a, b = b, a % b
#     return b


## 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

def many_lcm(l):
    for i in range(len(l)-1):
        if i == 0:
            ans = lcm(l[0], l[1])
        else:
            ans = lcm(l[i+1], ans)
    return ans
N = INT()
A = LIST()

lm = many_lcm(A)
# print(l)
B = []
for a in A:
    B.append(lm // a)
print(sum(B) % mod)





### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# from functools import reduce
# from math import gcd as gcd_base  # from fractions import gcd
# gcd = lambda *numbers: reduce(gcd_base, numbers)  # 3 数以上の最大公約数

# lcm_base = lambda x, y: (x * y) // gcd_base(x, y)
# lcm = lambda *numbers: reduce(lcm_base, numbers, 1)  # 3 数以上の最小公倍数
# 最小公倍数
# def gcd(a, b):
#     if a < b:
#         a, b = b, a
#     while a % b != 0:
#         a, b = b, a % b
#     return b



def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = tmp * l[i]//gcd(tmp, l[i])
    return tmp
N = INT()
A = LIST()

lm = many_lcm(A)
ans = 0
for a in A:
    ans += lm // a
    
print(ans % mod)
n,l=[int(x) for x in input().split()]
b=[input() for x in range(n)]
b.sort()
print(''.join(b))

### FIXED CODE ###

ABC=list(map(int,input().split()))
ABC.sort()

if ABC[0]==5 and ABC[1]==5 and ABC[2]==7:
	print("YES")
else:
	print("NO")
N = int(input())
S = 0
for i in range(1, N+1):
  S += i
print(S)

### FIXED CODE ###

IN = input()
OUT = []

for order in IN:
    if order == "B" and len(OUT) != 0:
        OUT.pop()
    elif order == "0" or order == "1":
        OUT.append(order)

print("".join(OUT))
S = list(input().rstrip())
ans = Counter(S)
print("Yes") if len(ans)==2 & list(ans.values())[0]==2 & list(ans.values())[1]==2 else print("No")

### FIXED CODE ###

from collections import Counter
S = list(input().rstrip())
ans = Counter(S)
print("Yes") if len(ans)==2 & list(ans.values())[0]==2 & list(ans.values())[1]==2 else print("No")
while True:
    a = int(input())
    if a == 0:
        break

    i = 1
    print("Case {}: {}.format(i,a))
    i += 1

### FIXED CODE ###

i=0
while True:
    a = int(input())
    if a == 0:
        break
    i += 1
    print("Case {}: {}".format(i,a))
lst=['A','B','C','D','E','F']
a=input()
if lst.index(a[0])>lst.index(a[1]):
    print('>')
elif lst.index(a[0])==lst.index(a[1]):
    print('=')
else:
    print('<')

### FIXED CODE ###

lst=['A','B','C','D','E','F']
a=input()
if lst.index(a[0])>lst.index(a[2]):
    print('>')
elif lst.index(a[0])==lst.index(a[2]):
    print('=')
else:
    print('<')
def main():

    N, K = map( int, input().split())
    if K == 1:
        print(0)
        return
    A = list( map( int, input().split()))
    A.sort()
    ans = 0

    cnt = 1
    for i in range(K-1,N):
        if i >= K:
            cnt *= i*pow(i-(K-1), Q-2, Q)%Q
            cnt %= Q
        ans += cnt*A[i]

        ans -= cnt*A[N-1-i]
        ans %= Q
    print(ans)
    
if __name__ == '__main__':
    main()


### FIXED CODE ###

#import sys
#input = sys.stdin.readline
Q = 10**9+7
# def getInv(N):#Qはmod
#     inv = [0] * (N + 1)
#     inv[0] = 1
#     inv[1] = 1
#     for i in range(2, N + 1):
#         inv[i] = (-(Q // i) * inv[Q%i]) % Q
#     return inv

def main():

    N, K = map( int, input().split())
    if K == 1:
        print(0)
        return
    A = list( map( int, input().split()))
    A.sort()
    ans = 0

    cnt = 1
    for i in range(K-1,N):
        if i >= K:
            cnt *= i*pow(i-(K-1), Q-2, Q)%Q
            cnt %= Q
        ans += cnt*A[i]

        ans -= cnt*A[N-1-i]
        ans %= Q
    print(ans)
    
if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))

Num=[0]*(N+1)

for i in A:
    Num[A[i]]+=1

for i in range(1,N+1):
    print(Num[i])

### FIXED CODE ###


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

A.sort()
if A[0]==0:
    A.remove(0)

l=len(A)
k=0

ans=1

m=max(A)

for i in range(l-1):
    if A[i+1]>A[i]:
        k=A[i]
        print(ans)
        while A[i+1]!=k+1:
            k=k+1
            print(0)
        ans=1
    else:
        ans=ans+1
if A[l-1]==A[l-2]:
    print(ans)
else:
    print(ans)
    
   
for j in range(m+1,N+1):
    print(0)
N,K= map(int, input().split())
x = list(map(int, input().split()))
x.sort()
t = max(x)
y = x[0]
s = []
for i in range(1,len(x)):
    s.append(x[i]-x[i-1])
s.sort()
m = min(y,s[0])
if t>= K and K%m==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



### FIXED CODE ###

N,K= map(int, input().split())
x = list(map(int, input().split()))
x = list(set(x))
x.sort()
t = max(x)
y = x[0]
s = [1000000000000]
o=0
if x[0] == K:o=1
for i in range(1,len(x)):
    s.append(x[i]-x[i-1])
    if x[i] == K:o = 1
s.sort()
m = min(y,s[0])
if (t>= K and K%m==0) or o==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
n = int(input())
edge = [[] for i in range(n)]
colors = [-1] * n
for i in range(n-1):
    u, v, w = [int(item) for item in input().split()] 
    u -= 1
    v -= 1
    edge[u].append([v, w%2])
    edge[v].append([u, w%2])

def dfs(frm, n):
    for tv, tw in edge[n]:
        if tv == frm:
            continue
        else:
            if tw == 1:
                colors[tv] = (colors[frm] + 1) % 2
            else:
                colors[tv] = colors[frm]
            dfs(n, tv)

colors[0] = 0
dfs(0, 0)
for item in colors:
    print(item)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n = int(input())
edge = [[] for i in range(n)]
colors = [0] * n
for i in range(n-1):
    u, v, w = [int(item) for item in input().split()] 
    u -= 1
    v -= 1
    edge[u].append([v, w%2])
    edge[v].append([u, w%2])

def dfs(frm, n, d):
    for tv, tw in edge[n]:
        if tv == frm:
            continue
        else:
            td = (d + tw) % 2
            if td == 1:
                colors[tv] = 1 
            else:
                colors[tv] = 0 
            dfs(n, tv, td)
    return True

colors[0] = 0
dfs(0, 0, 0)
for item in colors:
    print(item)