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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or t==2 and (i==0 or i==12):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else 24-t
        newTime[nt] += 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t==1:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,gaps[j+1]-gaps[j])
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[1])
    ans = max(ans, res)
print(ans)



### FIXED CODE ###

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

T = [0]*13
T[0] = 1
for d in D:
    T[d] += 1


Times = [0]*24
ones =[]
for i,t in enumerate(T):
    if t>=3 or (t==2 and (i==0 or i==12)):
        print(0)
        exit()
    elif t==2:
        Times[i] = 1
        Times[24-i] = 1
    elif t==1:
        ones.append(i)

ans = 0
L = len(ones)
for i in range(2**L):
    stats = [False]*L
    temp = i
    for j in range(L):
        stats[j] = temp&1
        temp >>= 1
    
    newTime = [t for t in Times]
    res = 10**9
    for j,t in enumerate(ones):
        nt = t if stats[j] else (24-t)%24
        newTime[nt] = 1
    
    gaps = []
    for j,t in enumerate(newTime):
        if t!=0:
            gaps.append(j)
    for j in range(len(gaps)-1):
        res = min(res,min(gaps[j+1]-gaps[j],gaps[j]+24-gaps[j+1]))
    if len(gaps)>=2:
        res = min(res, gaps[0]+24-gaps[-1])
    ans = max(ans, res)
print(ans)
N,Y = map(int,input().split())
for i in range(N):
  for j in range(N):
    for k in range(N):
      if i*10000 + j*5000 + k*1000 == Y:
        print(i + " " + j + " " + k)
        break
else:
  print("-1 -1 -1")

### FIXED CODE ###

N,Y = map(int,input().split())
for i in range(N+1):
  for j in range(N-i+1):
    k = N-i-j
    if i*10000 + j*5000 + k*1000 == Y:
      print(i,j,k)
      exit()
print("-1 -1 -1")
[ print(["YES", "NO"][0 if i[0] ** 2 + i[1] ** 2 == i[2] ** 2 else 1]) for i in [sorted([int(x) ** 2 for x in input().split()])] for _ in range(int(input()))]

### FIXED CODE ###

[print("YES" if i[0] + i[1] == i[2] else "NO") for _ in range(int(input())) for i in [sorted([int(x) ** 2 for x in input().split()])]]
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]>=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]<root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)

### FIXED CODE ###

N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]>root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)
N=input()
A=len(set(N))
if A==2 and N.count(A[0]) == N.count(A[1]) == 2:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N=input()
A=len(set(N))
if A==2 and N.count(N[0]) == N.count(N[1]) == 2:
    print("Yes")
else:
    print("No")
X, A, B = map(int, input().split())
print((X - A) % B)

### FIXED CODE ###

print((int(input()) - int(input())) % int(input()))
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
ans = 1
C = []
for i in range(1,int(S**0.5+1)):
    if S%i == 0:
        C.append(i)
        C.append(S//i)
for c in C:
    B = np.array(A) % c
    B.sort()
    hoge = 0
    for i in range(N):
        hoge += B[i]
        if hoge <= K and hoge == -sum(B[i+1:]-c):
            ans = max(ans,c)
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
ans = 1
C = []
for i in range(1,int(S**0.5+1)):
    if S%i == 0:
        C.append(i)
        C.append(S//i)
for c in C:
    B = []
    for i in A:
        B.append(i%c)
    B.sort()
    hoge = 0
    sum_b = sum(B)
    for i in range(N):
        hoge += B[i]
        sum_b -= B[i]
        if hoge <= K and hoge == c*(N-i-1)-sum_b:
            ans = max(ans,c)
print(ans)
n, k, x, y = map(int, input().split())
basic = min(k * x, n * x)
plus = max((n - k) * y, 0)
print(basic + plus)

### FIXED CODE ###

n, k, x, y = [int(input()) for i in range(4)]
basic = min(k * x, n * x)
plus = max((n - k) * y, 0)
print(basic + plus)
n, k = map(int, input().split())
stones = list(map(int, input.split()))

dp = [False for _ in range(k+1)]

for i in range(1, k+1):
  for j in stones:
    if i >= j and dp[i-j] == False:
      dp[i] = True
      continue
      
if dp[k]:
  print('First')
else:
  print('Second')

### FIXED CODE ###

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

dp = [False for _ in range(k+1)]

for i in range(1, k+1):
  for j in stones:
    if i >= j and dp[i-j] == False:
      dp[i] = True
      continue
      
if dp[k]:
  print("First")
else:
  print("Second")
Z = int(input())
n = (-2)

ans = ""

while abs(Z) >= 1:
  r = Z % n
  if r < 0:
    r = r + 2
  Z = int((Z - r) / n)
  ans += str(r)

ans = "".join(list(reversed(ans)))

print(int(ans))

### FIXED CODE ###

Z = int(input())

if Z == 0:
  print(0)

else:
  n = (-2)

  ans = ""

  while abs(Z) >= 1:
    r = Z % n
    if r < 0:
      r = r + 2
    Z = int((Z - r) / n)
    ans += str(r)

  ans = "".join(list(reversed(ans)))


  print(int(ans))
N = raw_input()
keys = ['+','-']
x = 0
check = True

for key1 in keys:
    if key1 == '+' and check:
        x = int(N[0]) + int(N[1])
    elif(key1 == '-' and check):
        x = int(N[0]) - int(N[1])
    for key2 in keys:
        if key2 == '+' and check:
            x = x  + int(N[2])
        elif(key2 == '-' and check):
            x = x  - int(N[2])
            
        for key3 in keys:
            if key3 == '+' and check:
                x = x  + int(N[3])
                if (x == 7):
                    ans = N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    #print N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False
                else:
                    x = 0
            elif(key3 == '-' and check):
                x = x  - int(N[3])

                if (x == 7):
                    ans =  N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False

                else:
                    x = 0
print ans

### FIXED CODE ###

N = raw_input()
keys = ['+','-']
x = 0
check = True
ans = ''
for key1 in keys:
    if key1 == '+' and check:
        x1 = int(N[0]) + int(N[1])
    elif(key1 == '-' and check):
        x1 = int(N[0]) - int(N[1])
    for key2 in keys:
        if key2 == '+' and check:
            x2 = x1  + int(N[2])
        elif(key2 == '-' and check):
            x2 = x1  - int(N[2])
        
        #print x
        for key3 in keys:
            if key3 == '+' and check:
                #print x
                #print int(N[3])
                x3 = x2  + int(N[3])
                #print x
                if (x3 == 7):
                    ans = N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False


            elif(key3 == '-' and check):

                x3 = x2  - int(N[3])

                if (x3 == 7):
                    ans =  N[0] + key1 + N[1] + key2 + N[2] + key3 + N[3]+ '=7'
                    check = False

            #print x
print ans
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    n = int(stdin.readline()[:-1])   
    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)]
    a = list(map(int, r.split()))
    #a, b = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]

    res = 1
    import numpy as np
#    d = [i for i in a if ma != i or mi != i]
    b = (np.array(a[1:]) - np.array(a[:-1]))
    res += sum(1 for x in b if x <= 0)
    print(res)

#    for i in range(1,a):
#        for j in range(0,a-1):
#            a[i]
#    b = a[1:] - a[:1]
#    res = 
#    print(res)
#    ans = sum(1 for x in res if x <= 0)
#    print(ans)
#    for i in range(1,len(a)):
#        if i >= a[i]:
#            res += 1
#    print(res)

    #'Yes', 'No', 'YES', 'NO', ':(', 'Yay!'
    #res = 0
    #a, b = map(int, r.split())
    #print()

if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    n = int(stdin.readline()[:-1])   
    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)]
    a = list(map(int, r.split()))
    #a, b = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]

    res = 1
    bk = a[0]
    for i in range(1,n):
        if bk >= a[i]:
            bk = a[i]
            res += 1
    print(res)


#    b = [0]*n
#    for i in range(n):
#        b[a[i]-1] = i

#    res = 0
#    mem = b[0]
#    for i in range(1,n):
#        if mem <= b[i]:
#            print(b[i])
##            mem = b[i]
#        else:
#            res += 1
#    print(res)

if __name__ == '__main__':
    main()
S=list(input())
a=0
for i in range(len(S):
  if S[i]=='W':
    a+=L[:i].count('B')
print(a)
    
    

### FIXED CODE ###

S=input()[::-1]
ans,tmp=0,0
for i in S:
  if i=='W':
    tmp+=1
  else:
    ans+=tmp
print(ans)
a = int(input())
l = list(str(a))
for s in l:
  if s === '7':
    print('Yes')
    break
  else if l[2] != '7':
    print('No')

### FIXED CODE ###

a = str(input())
if '7' in a:
  print('Yes')
else:
  print('No')
def main():
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

    for i in range(N-1):
        a, b = map(int, input().split())
        E[a].append(b)
        E[b].append(a)

    def mktree(v, parent, E):
        children = E[v]
        if parent not in children:
            return
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    for child in E[1]:
        mktree(child, 1, E)

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    get(1, E, counter)
    print(" ".join(str(x) for x in counter[1:]))

main()






### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(2*10**5)
    N, Q = map(int, input().split())
    E = [[] for i in range(N+1)]
    counter = [0] * (N+1)

    for i in range(N-1):
        a, b = map(int, input().split())
        E[a].append(b)
        E[b].append(a)

    for i in range(Q):
        # 頂点p を根とする部分木に含まれるカウンターにxを足す
        p, x = map(int, input().split())
        counter[p] += x

    queue = []

    parent = [1]
    def mktree(v, parent, E):
        children = E[v]
        children.remove(parent)
        for child in children:
            mktree(child, v, E)

    while parent:
        p = parent.pop()
        for child in E[p]:
            E[child].remove(p)
            parent.append(child)

    def get(v, children, counter):
        c = counter[v]
        for child in children[v]:
            counter[child] += c
            get(child, children, counter)

    parent = [1]
    while parent:
        p = parent.pop()
        c = counter[p]
        for child in E[p]:
            counter[child] += c
            parent.append(child)

    print(" ".join(str(x) for x in counter[1:]))

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

input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = [*map(int, input().split())]
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)

### FIXED CODE ###

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

#input = __import__('sys').stdin.readline
N, X = map(int, input().split())
l = list(map(int, input().split()))
res = -1

for i in range(N):
    d = abs(l[i] - X)
    
    if res == -1:
        res = d
    else:
        res = gcd(res, d)

print(res)
n,k = map(int, input().split())
nums = []
for i in range(n):
    nums.append(int(input()))

count = 0
for n in nums:
  if n > k:
    count +1
  else:
    continue
print(count)

### FIXED CODE ###

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

count = 0
for n in nums:
  if n >= k:
    count +=1
  else:
    continue
print(count)
N = int(input())
A = list(map(int, input().split()))

Q = int(input())

s = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    diff = c - A[b - 1]
    A[b - 1] = c
    s += diff
    print(s)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ma = [0] * (100000 + 1)

for i in range(N):
    ma[A[i]] += 1

Q = int(input())

s = sum(A)

for i in range(Q):
    b, c = map(int, input().split())
    diff = c * ma[b] - ma[b] * b
    ma[c] += ma[b]
    ma[b] = 0
    s += diff
    print(s)
s = str(input())

print("{}{}{}".format(s[0], len(s) - 2), s[-1])


### FIXED CODE ###

s = str(input())

print("{}{}{}".format(s[0], len(s) - 2, s[-1]))
N = input() 
A = list(map(int,input().split()))
c = 1
i = 0
for i in N-1:
    if c *= A[i] >= 10**18:
        print(-1)
        exit()
  
print(c)



### FIXED CODE ###

n=int(input())
ls=[int(s) for s in input().split(" ")]

if 0 in ls:
  print(0)
else:
  num=1
  for i in ls:
    num*=i
    if num>10**18:
      num=-1
      break

  print(num)
N, M, L = map(int,input().split())
ABC = [list(map(int, input().split())) for _ in [0] * M]
Q = int(input())
ST = [list(map(int, input().split())) for _ in [0] * Q]


INF = (L + 1) * N
d = [[INF] * N for _ in [0] * N]
for i in range(N):
    d[i][i] = 0
for a, b, c in ABC:
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d, N=None):
    if N is None:
      N = len(d)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

Warshall_Floyd(d, N)

d2 = [None] * N
for i, row in enumerate(d):
    d2[i] = [1 if e <= L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2, N)

for s, t in ST:
    s -= 1
    t -= 1
    ans = (d2[s][t] % INF) - 1
    print(ans)

### FIXED CODE ###

A, B = map(int, input().split())
diff = A - 2 * B
if diff > 0:
  print(diff)
else:
  print(0)
import sys

length = int(sys.stdin.readline())
num_seq = sys.stdin.readlines()

for i in range(1,length):
    print(num_seq[length - i],end=' ')
print(num_seq[0],end='')


### FIXED CODE ###

import sys

length = int(sys.stdin.readline())
num_seq = sys.stdin.readline().split()

for i in range(1, length):
    print(num_seq[length - i], end=' ')
print(num_seq[0])
n,r=(int,input().split())
print(r if n>=10 else r+(100*(10-n)))

### FIXED CODE ###

n,r=map(int,input().split())
if(n>=10):
  print(r)
else:
  print(r+(100*(10-n)))
s = input()
count = 0
while True:
    for i,n in enumerate(s):
        if s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            count += 2
            break
    else:
        break
print(count)

### FIXED CODE ###

S = input()
a = []
for s in S:
    if not a:
        a.append(s)
        continue
    if s != a[-1]:
        a.pop()
    else:
        a.append(s)
print(len(S)-len(a))
# -*- coding: utf-8 -*-
print(re.sub('[a-z]', 'x', input()))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import re
s = input()
print(re.sub('[a-z]', 'x', s))
import math

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

ans = 0
MOD = 10**9 + 7

fact = math.factorial(n-1)

p = [0]*(n-1)
p[0] = 1 * fact%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + (fact/(i+1))%MOD
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])*p[i]
    ans %= MOD

ans %= MOD

print(int(ans))


### FIXED CODE ###

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


def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod

ans = 0
MOD = 10**9 + 7

factorial = 1
for i in range(2,n):
    factorial = (factorial * i%MOD) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + factorial*mod_inv(i+1,MOD)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])%MOD*p[i]
    ans %= MOD

print(int(ans))
a=input()
b=input()

### FIXED CODE ###

a,b=map(int, raw_input().split())
c=a*b 
d=2*(a+b)
print c,d
a = input().split()[0]
b = input().split()[1]
a = int(a)
b = float(b)

print(int(a*b))

### FIXED CODE ###

l = input().split()
 
a = l[0]
b = l[1]
 
a = int(a)
b = float(b) * 1000
b = int(b)
ks = a * b 
print(int(ks // 1000))
s = list(map(int, input()))
c = 0
count = 0
while(c==0):
  for i in range(len(s)):
    if sum(s) == len(s) or sum(s) == 0:
      c=1
      break
    if i == len(s)-1:
      break
    if len(s) == 2 and sum(s) == 1:
      count+=2
      c=1
      break  
    if s[i] + s[i+1] == 1:
      del s[i]
      del s[i]
      count += 2
      if len(s) == i+1:
        break

print(count)    
  

### FIXED CODE ###

s = list(map(int, input()))
c1,c0=0,0
for i in s:
  if i==1:
    c1+=1
  if i==0:
    c0+=1  
print(len(s)-abs(c1-c0))
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    for i in range(n):
        x, y = graph[i]
        bl = np.all((comb[:, i][:, None] ^ 1) | (comb[:, x-1] == y), axis=1)
        comb = comb[bl]
    print(np.amax(comb.sum(axis=1)))

if __name__ ==  '__main__':
    main()


### FIXED CODE ###

import sys
# import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for j in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x-1, y))

# xy = np.array(xy)
# x, y = xy[:, :].T
# x = x.T 
# y = y.T

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        ok = True
        for i in range(n):
            if not comb >> i & 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    ok = False
                    break
            if ok:
                cnt += 1
            else:
                break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13
l=len(t)
for n,c in enumerate(t):
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mulmod+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(i*mulmod+int(c))%13
            e[k]+=d[int(c)]
            e[k]%=mod
    d=e
    mul*=10
    mulmod=mul%13
print(d[5])


### FIXED CODE ###

# coding: utf-8
# Your code here!
 
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
 
s = input()
l = len(s)
MOD = 10**9+7
 
dp = [0]*13
dp[0] = 1
for i in s:
    new = [0]*13
    if i == "?":
        for i in range(10):
            for j in range(13):
                new[(10*j+i)%13] += dp[j]
    else:
        i = int(i)
        for j in range(13):
            new[(i+10*j)%13] += dp[j]
    
    for i in range(13):
        new[i] %= MOD
    dp,new = new,dp
#    print(dp)
 
print(dp[5]%MOD)
w,h= map(int, raw_input().split())
p =[]
q = []
for i in xrange(w):
    t = input()
    p.append(t)

for i in xrange(h):
    t = input()
    q.append(t)
p =sorted(p,reverse=True)
q =sorted(q, reverse=True)
ac = p[:]
acq = q[:]
i = w-2
while i >=0:
    ac[i] += ac[i+1]
    i -=1
i = h - 2
while i >= 0:
    acq[i] += acq[i + 1]
    i -= 1
c = ac[0] + acq[0]
k = 0
# for i in xrange(h):
i = 0
while i < h:
    # for j in xrange(k,w):
        j = k
        if q[i] > p[j]:
            c += ac[j]
            i += 1
            # break
        else:
            c +=acq[i]
            k +=1
        # c += q[i]
print c

### FIXED CODE ###

w,h= map(int, raw_input().split())
p =[]
q = []
for i in xrange(w):
    t = input()
    p.append(t)

for i in xrange(h):
    t = input()
    q.append(t)
p =sorted(p,reverse=True)
q =sorted(q, reverse=True)
ac = p[:]
acq = q[:]
i = w-2
while i >=0:
    ac[i] += ac[i+1]
    i -=1
i = h - 2
while i >= 0:
    acq[i] += acq[i + 1]
    i -= 1
c = ac[0] + acq[0]
k = 0
# for i in xrange(h):
i = 0
while i < h:
    # for j in xrange(k,w):
        j = k
        # print i,j
        if j >= w:
            break
        if q[i] > p[j]:
            c += ac[j]
            i += 1
            # break
        else:
            c +=acq[i]
            k +=1
        # c += q[i]
print c
n, k = inpl()
p = inpl()
p = sorted(p)
ans = 0
for i in range(n):
    ans += p[i]
    if i+1 == k:
        break
print(ans)

### FIXED CODE ###

from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n, k = inpl()
p = inpl()
p = sorted(p)
ans = 0
for i in range(n):
    ans += p[i]
    if i+1 == k:
        break
print(ans)