Harryxun/stf_run huggingface dataset:
N = int(input())
a = list(map(int, input().split()))

def resolve(a):
    target = N
    result = 0
    for i in a:
        if target > i: target = i
        result += target
    return result

print(sum([resolve(a[x:]) for x in range(N)]))


### FIXED CODE ###

s = raw_input()
T = S = 0
for i in s:
    if i == "T":
        if S: S -= 1
        else: T += 1
    elif i == "S":
        S += 1
print T + S
A = int(input())
B = int(input())

if max(A, B) <= 8:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

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

if max(A, B) <= 8:
    print("Yay!")
else:
    print(":(")
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	if remain > int(a * 2): 
		b = b + int( a / 4) * 8
		a = a % 4
	return a,b
	
while True:
	N,Y = map(int,input().split())
	
	a = int(Y/10000)
	b = int((Y - a * 10000)/5000)
	c = int((Y - a * 10000 - b * 5000)/1000)
	
	max_bills = int(Y/1000)
	
	if (max_bills < N) or (N < a + b + c):
		print('-1 -1 -1')
		
	elif (N == max_bills):
		print('0 0 ' + str(max_bills))
		
	elif (N == a + b + c):
		abc_exp(a,b,c)
	
	else:
		remain = N - a - b - c
		if remain % 4 == 0:
			a,b = exchange(a,b,remain)
			remain = N - a - b - c
			if b - remain/4 > 0:
				b = b - int(remain / 4)
				a = a + int(remain / 4) * 5
				abc_exp(a,b,c)
		
		else:
			a = a - (remain % 4)
			b = b + 2 * (remain % 4)
			a , b = exchange(a,b,remain)
			remain = N - a - b - c
			if b - remain/4 > 0:
				b = b - int(remain / 4)
				c = c + int(remain / 4) * 5
				abc_exp(a,b,c)

### FIXED CODE ###

def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	#if remain >= int(a * 2): 
	#	b = b + int(a / 4) * 8
	#	a = a % 4
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

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

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
elif (N == a + b + c):
	abc_exp(a,b,c)

else:
	remain = N - a - b - c
	if remain % 4 == 0:
		a,b = exchange(a,b,remain)
		remain = N - a - b - c
		if not b - remain/4 < 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
	
	else:
		a = a - (remain % 4)
		b = b + 2 * (remain % 4)
		a , b = exchange(a,b,remain)
		remain = N - a - b - c
		if b - remain/4 >= 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
		
		else:
			print('-1 -1 -1')
from bisect import bisect_left as bl
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
for i in range(m):
    b,c=map(int,input().split())
    t=bl(a,c)
    print(a)
    if t<=b:
        a=[c]*t+a[t:]
    else:
        a=a[b:t]+[c]*b+a[t:]
print(sum(a))

### FIXED CODE ###

n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
k=sorted([list(map(int,input().split()))for i in range(m)],key=lambda x:-x[1])+[[0,0]]
c,d=0,0
t=0
ans=0
while c<n:
    if a[d]>=k[t][1]:
        ans+=a[d]
        d+=1
        c+=1
    else:
        ans+=k[t][1]*min(n-c,k[t][0])
        c+=k[t][0]
        t+=1
print(ans)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))

    return count


### FIXED CODE ###

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


def hoge():
    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))
    return count


print(hoge())
N = int(input())

print((n*(n-1))/2)

### FIXED CODE ###

N = int(input())
print((N*(N-1))//2)
H,W = list(map,int(input().split()))

for i in range(H):
  C = input()
  print(C)
  print(C)

### FIXED CODE ###

a = list(map(int,input().split()))
for i in range(a[0]):
  b = input()
  print(b)
  print(b)
a,b = int(input())


if a>9 or b>9:
    print(a*b)
else:
    print(-1)

### FIXED CODE ###

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

if a<10 and b<10:
    print(a*b)
else:
    print(-1)
input_str = raw_input()
N, K = [int(x) for x in input_str[0].split(' ')]

x_grid = set()
y_grid = set()
d_grid = set()

for line in input_str[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x_grid.add(x1)
    x_grid.add(x2)
    y_grid.add(y1)
    y_grid.add(y2)
    d_grid.add(d1)
    d_grid.add(d2)

x_grid = sorted(x_grid)
y_grid = sorted(y_grid)
d_grid = sorted(d_grid)
x_grid_index = {x[1]:x[0] for x in enumerate(x_grid)}
y_grid_index = {y[1]:y[0] for y in enumerate(y_grid)}
d_grid_index = {d[1]:d[0] for d in enumerate(d_grid)}

fish_dist = np.zeros( (len(x_grid), len(y_grid), len(d_grid)), dtype=int )

for line in input_str[1:]:
    x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
    x1_index = x_grid_index[x1]
    x2_index = x_grid_index[x2]
    y1_index = y_grid_index[y1]
    y2_index = y_grid_index[y2]
    d1_index = d_grid_index[d1]
    d2_index = d_grid_index[d2]
    fish_dist[x1_index:x2_index, y1_index:y2_index, d1_index:d2_index] += 1

volume = 0
for (x_index, y_index, d_index), num in np.ndenumerate(fish_dist):
    if num >= K:
        x_begin = x_grid[x_index]
        y_begin = y_grid[y_index]
        d_begin = d_grid[d_index]
        x_end = x_grid[x_index + 1]
        y_end = y_grid[y_index + 1]
        d_end = d_grid[d_index + 1]
        volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
print volume

### FIXED CODE ###

import itertools

def main():
    input_lines = []
    input_lines.append(input())
    N, K = [int(x) for x in input_lines[0].split(' ')]
    for i in range(N):
        input_lines.append(input())

    grid = [set() for i in range(3)]
    data = []
    for line in input_lines[1:]:
        x1, y1, d1, x2, y2, d2 = [int(x) for x in line.split(' ')]
        data.append((x1, y1, d1, x2, y2, d2))
        grid[0].add(x1)
        grid[0].add(x2)
        grid[1].add(y1)
        grid[1].add(y2)
        grid[2].add(d1)
        grid[2].add(d2)

    grid = [sorted(g) for g in grid]
    grid_index = [{x[1]:x[0] for x in enumerate(g)} for g in grid]
    grid_len = [len(g) for g in grid]

    fish_dist = [[[0 for i in range(grid_len[2])] for i in range(grid_len[1])] for i in range(grid_len[0])]

    for x1, y1, d1, x2, y2, d2 in data:
        x1_index = grid_index[0][x1]
        x2_index = grid_index[0][x2]
        y1_index = grid_index[1][y1]
        y2_index = grid_index[1][y2]
        d1_index = grid_index[2][d1]
        d2_index = grid_index[2][d2]
        for x_index, y_index, d_index in itertools.product( range(x1_index, x2_index), range(y1_index, y2_index), range(d1_index, d2_index) ):
            fish_dist[x_index][y_index][d_index] += 1

    volume = 0
    for x_index, y_index, d_index in itertools.product(range(grid_len[0]), range(grid_len[1]), range(grid_len[2])):
        if fish_dist[x_index][y_index][d_index] >= K:
            x_begin = grid[0][x_index]
            y_begin = grid[1][y_index]
            d_begin = grid[2][d_index]
            x_end = grid[0][x_index + 1]
            y_end = grid[1][y_index + 1]
            d_end = grid[2][d_index + 1]
            volume += (x_end - x_begin) * (y_end - y_begin) * (d_end - d_begin)
    print(volume)

main()
N = int(input())
C = list(map(int, input().split()))

C.sort()

ans = 0

mod = 10 ** 9 + 7

pattern = (2 ** (N - 2)) % mod

if N != 1:
    for i in range(N):
        c = C[i]
        ans += c * (N + 1 - i) * pattern
        ans %= mod
    ans *= 2 ** N
else:
    ans = C[0] * 2

ans %= mod

print(ans)

### FIXED CODE ###

K, X = map(int, input().split())

if K * 500 >= X:
  print("Yes")
else:
  print("No")
sum=0
max=0
for i in range(5):
  x = int(input()）
  y = -(-x//10)*10

### FIXED CODE ###

X=[int(input()) for i in range(5)]
Y=[]
for x in X:
  Y.append(-(-x//10)*10-x)
print(sum(X)+sum(Y)-(max(Y)))
N,M=list(map(int, input().split()))
H=list(map(int, input().split()))
A=[list(map(int, input().split())) for _ in range(M)]

dp=[True]*N
a=[0]*N

for i in A:
  if H[i[0]-1]<H[i[1]-1] and a[i[1]-1]==0:
    dp[i[1]-1]=True
    dp[i[0]-1]=False
    a[i[0]-1]+=1
  elif H[i[0]-1]<H[i[1]-1] and a[i[1]-1]!=0:
    a[i[0]-1]+=1
    continue
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]==0:
    dp[i[1]-1]=False
    dp[i[0]-1]=True
    a[i[1]-1]+=1
  elif H[i[0]-1]>H[i[1]-1] and a[i[0]-1]!=0:
    a[i[1]-1]+=1
    continue
  elif H[i[0]-1]==H[i[1]-1]:
    dp[i[1]-1]=False
    dp[i[0]-1]=False
  

print(dp.count(True))

### FIXED CODE ###

S=input()

if S=="ABC":
  print("ARC")
  
else:
  print("ABC")
N=int(input())
l=list(map(int,input().split()))

if N==1:
    print("Yes")
    exit()

if N==2 and l[1]-l[0]<(-1):
    print("No")
    exit()
    

for i in range(N-2):
    if l[i+2]-l[i+1]<(0) and l[i+i]-l[i]<(0):
        print("No")
        exit()
    elif l[i+i]-l[i]<(-1):
        print("No")
        exit()

print("Yes")

### FIXED CODE ###

# coding: utf-8
# Your code here!

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

high=l[0]
for i in range(N-1):
    if l[i+1]-l[i]<(-1):
        print("No")
        exit()
    high=max(high,l[i+1])
    if l[i+1]<(high-1):
        print("No")
        exit()
        
print("Yes")
a = int(input())

b = []

for i in range(a-1):
    b.append((input().split()))

res = 0

for i in b:
    if (i[1] == 'BTC'):
        res += i[0]*380000
    else:
        res += i[0]

print(res) 

### FIXED CODE ###

a = int(input())

b = []

for i in range(a):
    b.append(input().split())

res = 0

for i in b:
    if (i[1] == 'BTC'):
        res += float(i[0])*380000
    else:
        res += int(i[0])

print(res)
n = int raw_input()
a = map(int, raw_input().split())
print min(a), max(a), sum(a)


### FIXED CODE ###

n = int(raw_input())
a = map(int, raw_input().split())
print min(a), max(a), sum(a)
osero = input();
len = len(osero);
con_b = 0;
con = 0;
for(i =0; i<len, i++) {
	if(osero[i]='B') {
		con_b++;
	}
	if(osero[i] ='W') {
		con = con + con_b;
	}
}
print(con)

### FIXED CODE ###

osero = input();
len = len(osero);
con_b = 0;
con = 0;
for i in range(0,len):
	if osero[i]=='B':
		con_b = con_b + 1;
	if osero[i] =='W':
		con = con + con_b;
print(con)
A,B,Q=map(int,input().split())
s=[]
t=[]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x=int(input())
  s1=s[:]
  s1.append(x)
  s1.sort()
  j=s1.index(x)
  if j==0:
    kouhoA=[s[j]]
  else:
    kouhoA=[s[j],s[j-1]]
  t1=t[:]
  t1.append(x)
  t1.sort()
  k=t1.index(x)
  if k==0:
    kouhoB=[t[k]]
  else:
    kouhoB=[t[k],t[k-1]]
  if j==0:
    
    if k==0:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if k==0:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)


### FIXED CODE ###

import bisect
A,B,Q=map(int,input().split())
s=[]
t=[]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x=int(input())
  j=bisect.bisect_left(s,x)
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  k=bisect.bisect_left(t,x)
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))

### FIXED CODE ###

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
print(max(kouho))
    







### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
b = [0] * N
c = [0] * N
b[0] = A[0]
c[-1] = A[-1]
for i in range(N-1):
    b[i+1] = math.gcd(b[i], A[i+1])
    c[-(i+2)] = math.gcd(c[-(i+1)], A[-(i+2)])

ans = 1
ans = max(c[1], ans)
ans = max(b[-2], ans)
for i in range(1, N-1):
    ans = max(math.gcd(b[i-1], c[i+1]), ans)
print(ans)
n = int(input())
if n == 1:
    print("Hello World")
    break
else:
    a = int(input())
    b = int(input())
    print(a + b)

### FIXED CODE ###


n = int(input())
if n == 1:
    print("Hello World")
    exit()
else:
    a = int(input())
    b = int(input())
    print(a + b)
a=[]
a=int(input().split())
for i in range(4):
 if a[i]==0:
  print(i)
 else:
  pass



### FIXED CODE ###

a=[]
a=input().split()
for i in range(5):
 if a[i]=='0':
   print(str(i+1))
 else:
   pass
import sys

X, Y = map(int, input().split())

if ((X + Y) % 3) != 0:
    print(0)
    sys.exit(0)

c = 0
check = 0
X_k, Y_k = X, Y
while c < max([X, Y]):
    if (X_k / 2) == Y_k:
        check = 1
        c_r = Y_k
        break
    else:
        X_k -= 1
        Y_k -= 2
        c += 1

N = c + c_r
r = min([c, c_r])
fact = [1, 1]
inv = [0, 1] 
factinv = [1, 1]
p = 10 ** 9 + 7
for i in range(2, N+1):
    fact.append(fact[-1] * i % p)
    inv.append(-inv[p%i] * (p // i) % p)
    factinv.append(factinv[-1] * inv[-1] % p)
print(fact[N] * factinv[r] * factinv[N-r] % p)

### FIXED CODE ###

import sys

X, Y = map(int, input().split())

n = (2*Y-X) / 3
m = (2*X-Y) / 3

if (X + Y) % 3 != 0 or n < 0 or m < 0:
    print(0)
    sys.exit(0)

N = int(n + m)
r = int(min([n, m]))
p = 10**9 + 7
fact = [1, 1]
inv = [0, 1]
factinv = [1, 1]

for i in range(2, N+1):
    fact.append(fact[-1]*i % p)
    inv.append(-inv[p%i] * (p//i) % p)
    factinv.append(factinv[-1] * inv[-1] % p)

print(fact[N] * factinv[r] * factinv[N-r] % p)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

K = int(input())
S = input()
n = len(S)
ans = 0
for i in range(K+1):
    ans += cmb(i+n-1, n-1, mod) * pow(25, i) * pow(26, (K-i))
print(ans%mod)

### FIXED CODE ###

# F - Strivore
import sys
MOD = 10**9+7
K = int(input())
S = input()
l = len(S)
ans = 0
 
tmp = pow(26,K,MOD)
ans = tmp
waru = pow(26,-1,MOD)
 
for i in range(1,K+1):
    tmp = (tmp*25*waru)%MOD
    tmp = (tmp*(l-1+i)*pow(i,-1,MOD))%MOD
    ans = (ans+tmp)%MOD
 
print(ans)
a,v = input().split()
b,w = input().split()
t = input()
 
move_a = int(v) * int(t) + int(a)
move_b = int(w) * int(t) + int(b)
 
if move_a >= move_b:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = input()
print(s[0] + s[1] + s[2])
X, y, Z = map(int, input().split())
def solve():
  for i in range(int(X/Y)):
    if(X < i*Y+(i+1)*Z):
      print(i-1)
      return

solve()

### FIXED CODE ###

X, Y, Z = map(int, input().split())
def solve():
  for i in range(int(X/Y)+2):
    if(X < i*Y+(i+1)*Z):
      print(i-1)
      return

solve()
from functools import lru_cache
@lru_cache(maxsize=100000000)
def c(n,k): 
    return 1 if(k<=0 or n<=k) else ( c(n-1, k-1) + c(n-1, k) ) 

n,k=map(int,input().split())
a=sorted(map(int,input().split()))
num=c(n,k)
hoge=[]
while True:
    hoge.append(c(n-1,k-1))
    if n-1==k-1:
        break
    n-=1

ans=0
for i in range(len(hoge)):
    ans-=hoge[i]*a[i]
    ans+=hoge[i]*a[-i-1]
    ans%=1000000007
print(ans)

### FIXED CODE ###

def modpow(x,p,mod):
    ret=1
    for i in range(64):
        if (1<<i)&p:
            ret=ret*x%mod
        x=x*x%mod
    return ret

def inverse_table(n,mod):
    table=[]
    for i in range(0,n+1):
        table.append(modpow(i,mod-2,mod))
    return table

def factorial_table(n,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*i%mod)
    return table

def inverse_factorial_table(n,it,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*it[i]%mod)
    return table

it=inverse_table(10**5,1000000007)
ft=factorial_table(10**5,1000000007)
ift=inverse_factorial_table(10**5,it,1000000007)
def c(n,k,it,ft,mod):
    return ft[n]*ift[k]*ift[(n-k)]%mod
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
hoge=[]
while True:
    hoge.append(c(n-1,k-1,it,ft,1000000007))
    if n-1==k-1:
        break
    n-=1
ans=0
for i in range(len(hoge)):
    ans-=hoge[i]*a[i]%1000000007
    ans+=hoge[i]*a[-i-1]%1000000007
    ans%=1000000007
print(ans)
import numpy as np

N, Q = map(int,input().split())
S = str(input())
A = [list(map(int,input().split())) for i in range(Q)]

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""



### FIXED CODE ###

import numpy as np

N, Q = map(int,input().split())
S = str(input())
A = [list(map(int,input().split())) for i in range(Q)]

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""
n = int(input())
l = list(map(input().split()))

l.sort(reverse = True)

if len(l) == n:
  lm = l[0]

  del l[0]

  if int(lm) < sum(l):
    print('Yes')
  else:
    print('No')
else:
  print('No')


### FIXED CODE ###

n = int(input())
l = [int(i) for i in input().split()]

l.sort(reverse = True)

if len(l) == n:
  lm = l[0]

  del l[0]

  if int(lm) < sum(l):
    print('Yes')
  else:
    print('No')
else:
  print('No')
n = input()
queue1 = list(range(1,n+1))
queue2 = list(range(1,n+1))
count = [0] * n
for i in range(n):
  while queue1[i] % 2 == 0:
    count[i] += 1
    queue1[i] /= 2
print(queue2[max(count)])

### FIXED CODE ###

n = int(input())
import numpy as np
a = list(range(1,n+1))
b = list(range(1,n+1))
c = [0] * n
for i in range(n):
  while a[i] % 2 == 0:
    a[i] /= 2
    c[i] += 1
print(b[np.argmax(c)])
a = input()
print(a**3)

### FIXED CODE ###

a = int(input())
b = a ** 3
print(int(b))
a,b=input().split.
A=int(a)
B=int(b)
print((A-1)*(B-1))

### FIXED CODE ###

a,b=input().split()
A=int(a)
B=int(b)
print((A-1)*(B-1))
if __name__=="__main__":
    l = list(input())
    N = len(l)
    if N==1:
        print(1)
        exit()
    results = []
    for i in range(0,N-1):
        if not l[i]==l[i+1]:
            results.append(max(i+1,N-i-1))
    print(min(results))

### FIXED CODE ###

if __name__=="__main__":
    l = list(input())
    N = len(l)
    results = []
    for i in range(0,N-1):
        if not l[i]==l[i+1]:
            results.append(max(i+1,N-i-1))
    if len(results):
        print(min(results))
    else:
        print(N)
a, b, c = map(int, input().split())
print(f"{c} {a} {b}")

### FIXED CODE ###

a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))
X = int(input(N))
if X == 7 or X == 5 or X == 3:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

X = int(input())
if X == 7 or X == 5 or X == 3:
  print('YES')
else:
  print('NO')
ans=[]
for i in l:
    if 'peach' in i:
        ans.append(i.replace('peach','apple'))
    elif 'apple' in i:
        ans.append(i.replace('apple','peach'))
    else:
        ans.append(i)
print ' '.join(ans)

### FIXED CODE ###

l=map(str,raw_input().split())
ans=[]
for i in l:
    if 'peach' in i:
        ans.append(i.replace('peach','apple'))
    elif 'apple' in i:
        ans.append(i.replace('apple','peach'))
    else:
        ans.append(i)
print ' '.join(ans)
def main():
    from sys import stdin
    #r = stdin.readline()[:-1]
    r = stdin.readlines()

    if r[0] == '1':
        print('Hello World')
    else:
        print(r[1] + r[2])
   
if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    from sys import stdin
    #r = stdin.readline()[:-1]
    n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    if n == 1:
        print('Hello World')
    else:
        r = [int(stdin.readline()) for i in range(n)]
        print(r[0] + r[1])
   
if __name__ == '__main__':
    main()
a, b, c = map(int, input().split())
if b == "+":
    print(a + c)
else:
    print(a-c)

### FIXED CODE ###

a, b, c = input().split()
if b == "+":
    print(int(a) + int(c))
else:
    print(int(a) - int(c))