Harryxun/stf_run huggingface dataset:
# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())
if T[0] =="?":
    if T[1] =="?":
        T[0:2] ="PD"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i:i+2] ="PD"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))

### FIXED CODE ###

# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())

    
if T[0] =="?":
    if len(T) ==1 :
        T[0] ="D"
    elif T[1] =="?":
        T[0] ="P"
        T[1] ="D"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i] ="P"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))
#from scipy.misc import comb
from scipy.special import comb
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
for i in range(1,n):
    b = comb(a[0],a[i])
    if b >= ans:
        ans1 = a[i]
        ans = b
print(a[0],ans1)

### FIXED CODE ###

import math
n = int(input())
a = sorted(list(map(int,input().split())))
b = (a[-1]+1)//2
d = float("inf")
for i in a:
    if abs(b-i) < d:
        d = abs(b-i)
        ans = i
print(a[-1],ans)
n = int(input())

a = input()
b = input()
c = input()

ans = 0

for count in range(n):
    tmp = 0
    if a[count] == b[count]:
        if a[count] != c[count]:
            tmp += 1
    else:
        tmp += 1
        if (a[count] != c[count]) & (b[count] != c[count]):
            tmp += 1
    ans += tmp
    
print(ans)


### FIXED CODE ###

n,a,b = input().split()

n = int(n)
a = int(a)
b = int(b)

ans_max = min(a,b)

if (a + b) > n:
    ans_min = a + b - n 
else:
    ans_min = 0


print(ans_max, end=" ")
print(ans_min)
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: - x[1])
tmp = []
for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
for i in range(N):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
    else:
        break
print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: - x[1])
tmp = []
for B, C in BC:
    tmp += [C] * B
    if len(tmp) >= N:
        break
if len(tmp) < N:
    n = len(tmp)
else:
    n = N
for i in range(n):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
    else:
        break
print(sum(A))
N=int(input())
a = list(map(int, input().split()))
a2= sorted(a,reverse=True)

for i in range(N):
  if i%2==1:
    S+=a2[i]
    a.remove(max(a))
  else:
    S-=a2[i]
print(S)

### FIXED CODE ###

N=int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
S=0
for i in range(N):
  if i%2==0:
    S+=a[i]
  else:
    S-=a[i]
print(S)
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

N += 1

sum = 0
count = 1

for i in range(N):
  sum = sum + L[i]
  count += 1
  if sum > X:
    count -= 1
    break
  if sum >= X:
    break
print(count)

### FIXED CODE ###

N, X = map(int, input().split())
L = [int(i) for i in input().split()]

sum = 0
count = 1

for i in range(N):
  sum = sum + L[i]
  count += 1
  if sum > X:
    count -= 1
    break
  if sum >= X:
    break
print(count)
while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=n-1
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            int+=L[i]
    print ink

### FIXED CODE ###

while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=w
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink
a = input()
t = input()
if a == "H" and t == "H":
  print("H")
elif a == "H" and t == "D":
  print("D")
elif a == "D" and t == "H":
  print("D")
else:
  pass

### FIXED CODE ###

a, t = input().split()
if a == t:
  print("H")
else:
  print("D")
N=int(input())

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

color=[0,0,0,0,0,0,0,0]
alles=0

for i in range(N) :
    
    if a[i]<400 :
        color[0]+=1
    elif a[i]<800 :
        color[1]+=1
    elif a[i]<1200 :
        color[2]+=1
    elif a[i]<1600 :
        color[3]+=1
    elif a[i]<2000 :
        color[4]+=1
    elif a[i]<2400 :
        color[5]+=1
    elif a[i]<2800 :
        color[6]+=1
    elif a[i]<3200 :
        color[7]+=1
    else :
        alles+=1

        
while 0 in color :color.remove(0)
eight=int(8)

if alles>=8 :
    print(eight," ",eight)
elif alles+len(color)>8 :
    if alles>=len(color) :
        print(alles," ",eight)
    else :
        print(len(color)," ",eight)
else :
    if alles>=len(color) :
        print(alles," ",lem(color)+alles)
    else :
        print(len(color)," ",len(color)+alles)



### FIXED CODE ###


N=int(input())

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

color=[0,0,0,0,0,0,0,0]
alles=0

for i in range(N) :
    
    if a[i]<400 :
        color[0]+=1
    elif a[i]<800 :
        color[1]+=1
    elif a[i]<1200 :
        color[2]+=1
    elif a[i]<1600 :
        color[3]+=1
    elif a[i]<2000 :
        color[4]+=1
    elif a[i]<2400 :
        color[5]+=1
    elif a[i]<2800 :
        color[6]+=1
    elif a[i]<3200 :
        color[7]+=1
    else :
        alles+=1

        
while 0 in color :color.remove(0)


if len(color)==0 :
    print(int(1)," ",len(color)+alles)
else :
    print(len(color)," ",len(color)+alles)
N = int(input())
A = list(map(int, input().split()))
B = [0] * 100000
ans = 0
for i in range(N):
	if A[i] <= 100000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(100001):
	if B[i] < i:
		ans += B[i]
	else:
		ans += B[i] - i
print(ans)
	


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = [0] * 100001
ans = 0
for i in range(N):
	if A[i] <= 100000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(100001):
	if B[i] < i:
		ans += B[i]
	else:
		ans += B[i] - i
print(ans)
s = list(input().split())

if s[0] == s[1] and s[1] == s[2]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

s = list(input())

if s[0] == s[1] and s[1] == s[2]:
  print('No')
else:
  print('Yes')
N = int(input().strip())
ar = [N*[] for _ in range(N)]
for row in range(N):
  ar[row] = input().strip()

count = N*[0]
fullestRow = -1
maxCount = 0
for row in range(N):
  for col in range(N):
    if ar[row][col] == '#':
      count[row] += 1
  if count[row] > maxCount:
    maxCount = count[row]
    fullestRow = row

if maxCount == 0:
  print(-1)
else:
  req = 0
  for row in range(N):
    if ar[row][fullestRow] == '#':
      found = True
      break
  if not found:
    req += 1
  req += N - maxCount
  
  for col in range(N):
    for row in range(N):
      if ar[row][col] == '.':
        req+=1
        break
  print(req)

### FIXED CODE ###

N = int(input().strip())
ar = [N*[] for _ in range(N)]
for row in range(N):
  ar[row] = input().strip()

fullestRows = []
maxCount = 0
for row in range(N):
  count = 0
  for col in range(N):
    if ar[row][col] == '#':
      count += 1
  if count > maxCount:
    maxCount = count
    fullestRows = [row]
  elif count == maxCount:
    fullestRows.append(row)

if maxCount == 0:
  print(-1)
else:
  found = False
  req = 0
  for fr in fullestRows:
    for row in range(N):
      if ar[row][fr] == '#':
        found = True
        break
    if found:
      break
  if not found:
    req += 1
  req += N - maxCount
  
  for col in range(N):
    for row in range(N):
      if ar[row][col] == '.':
        req+=1
        break
  print(req)
import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, None).sum()

    if req < k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff)


### FIXED CODE ###

import numpy as np

def solve(n, k, aaa, fff):
  aaa = np.sort(aaa)
  fff = np.sort(fff)[::-1]
  
  l = 0
  r = 10**12
  while l<=r:
    m = (l+r)//2
    req = np.clip(aaa - m//fff, 0, None).sum()

    if req <= k:
      r = m-1
    else:
      l = m+1

  return l


N, K = map(int,input().split())
aaa = np.array(list(map(int,input().split())))
fff = np.array(list(map(int,input().split())))

print(solve(N, K, aaa, fff))
import math
from functools import reduce
def lcm_base(x, y):
    return int((x * y)/math.gcd(x, y))
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
nums= list(map(int,input().split()))
ans = 0
lcmnum= lcm(nums)-1
for num in nums:
    ans+=(int(lcmnum)%num)
print(ans)

### FIXED CODE ###

import math
from functools import reduce
import fractions
def lcm_base(x, y):
    return (x * y)//fractions.gcd(x, y)
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
nums= list(map(int,input().split()))
ans = 0
lcmnum= lcm(nums)-1
for num in nums:
    ans+=(int(lcmnum)%num)
print(ans)
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

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

P=[i for i in range(N+1)]
r=[0 for i in range(N+1)]

def find(a):
    if a==P[a]:
        pass
    else:
        return find(P[a])
        
def union(a,b,c):
    P[b]=a
    r[b]=c
    
def find2(a,b):
    if a==P[a]:
        return b+r[a]
    else:
        return find2(P[a],b+r[a])
L=[]
for i in range(M):
    a,b,c=map(int,input().split())
    union(a,b,c)
    L.append([a,b,c])
    
for i in range(1,N+1):
    r[i]=find2(i,0)
    
#print(r)
#print(P)

for i in L:
    if r[i[0]]!=r[i[1]]-i[2]:
        print(i)
        print("No")
        exit()
print("Yes")
    


### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

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

L=[[]for i in range(N+1)]
D=dict()
for i in range(M):
    l,r,d=map(int,input().split())
    L[l].append([r,d])
    L[r].append([l,-d])
    D[i]=(l,r,d)
    
C=["N" for i in range(N+1)]

def dfs(x):
    for i,j in L[x]:
        if C[i]=="N":
            C[i]=C[x]+j
            dfs(i)

for i in range(1,N+1):
    if C[i]=="N":
        C[i]=0
        dfs(i)
#print(C)
#print(D)
for i in range(M):
    l,r,d=D[i]
    if C[r]-C[l]!=d:
        print("No")
        exit()
print("Yes")
import sys
 
argv=sys.argv
 
x=[0]*3
for i in range(3):
	x[i]=(int)(argv[i+1])
    
print(x[2]-(x[0]-x[1]))

### FIXED CODE ###

x=input().split()

y=[0]*3

for i in range(3):
  y[i]=int(x[i])

ans=(y[2]-(y[0]-y[1]))

if ans>0:
  print(ans)
  
elif ans<=0:
  print(0)
from math import gcd
from functools import reduce
N, M = map(int, input().split())
a = list(map(int, input().split()))

half_a = [ai // 2 for ai in a]
L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
print((M - L) // (2 * L) + 1)


### FIXED CODE ###

from functools import reduce

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


def f(x):
    c = 0
    while x % 2 == 0:
        x //= 2
        c += 1
    return c


def gcd(x, y):
    return gcd(y, x % y) if y != 0 else x


nth = [f(ai) for ai in a]
if len(set(nth)) == 1:
    half_a = [ai >> 1 for ai in a]
    L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
    ans = (M - L) // (2 * L) + 1 if M >= L else 0
else:
    ans = 0
print(ans)
k = int(input())
a,b = map(int,input())
d = 0
for i in range(a,b+1):
  if i%k == 0:
    d = 3
    break
if d == 3:
  print('OK')
else:
  print('NG')

### FIXED CODE ###

k = int(input())
a,b=map(int,input().split())
count = 0
for i in range(a,b+1):
    if i%k == 0:
        count += 1
if count == 0:
    print("NG")
else:
    print("OK")
alpha = list('abcdefghijklmnopqrstuvwxyz') * 2

def create_caesar(word, num):
	new_word = ""
	for s in word:
		new_word += alpha[alpha.index(s) + num]
	return new_word

check_the = [create_caesar('the', i) for i in range(26)]
check_this = [create_caesar('this', i) for i in range(26)]
check_that = [create_caesar('that', i) for i in range(26)]
set_the = set(check_the)
set_this = set(check_this)
set_that = set(check_that)

while True:
	sentence = raw_input().split()
	sentence[-1] = sentence[-1].replace('.', '')
	ans = []
	set_sentence = set(sentence)
	if len(set_sentence & set_the)!= 0:
		num = check_the.index(list(set_sentence & set_the)[0])
	elif len(set_sentence & set_this)!= 0:
		num = check_this.index(list(set_sentence & set_this)[0])
	elif len(set_sentence & set_that)!= 0:
		num = check_that.index(list(set_sentence & set_that)[0])

	for s in sentence:
		ans.append(create_caesar(s, -num))

	print " ".join(ans) + "."

### FIXED CODE ###

import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
	while not('the' in s or 'that' in s or 'this' in s):
		s = s.translate(tbl)
	print s[:-1]
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x:x//400,A))
#print(A)
C = [0]*9
for a in A:
  if a>=8:
    C[8] +=1
  elif C[a]==0:
    C[a] = 1
#print(C[:-1])
mi = sum(C[:-1])
if mi == 0:
  mini = min(1,C[-1])
ma = min(8,mi+C[-1])
print(mini,ma)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x:x//400,A))
#print(A)
C = [0]*9
for a in A:
  if a>=8:
    C[8] +=1
  elif C[a]==0:
    C[a] = 1
#print(C[:-1])
mi = sum(C[:-1])
mini = mi
if mi == 0:
  mini = 1
ma = mi+C[-1]
print(mini,ma)
char_list = list(input())
count1 = 0
count2 = 0
if len(char_list) == 1:
    print(count)
else:
    for i in char_list:
        if i % 2 == 0
            if char_list[i] is "0"
                continue
            else:
                count1 += 1
        else:
            if char_list[i] is "1"
                continue
            else:
                count1 += 1
    for i in char_list:
        if i % 2 == 0
            if char_list[i] is "1"
                continue
            else:
                count2 += 1
        else:
            if char_list[i] is "0"
                continue
            else:
                count2 += 1
print(min(count1,count2))

### FIXED CODE ###

char_list = list(input())
count1 = 0
count2 = 0
if len(char_list) == 1:
    print(0)
else:
    for i in range(len(char_list)):
        if i % 2 == 0:
            if char_list[i] is "0":
                continue
            else:
                count1 += 1
        else:
            if char_list[i] is "1":
                continue
            else:
                count1 += 1
    for i in range(len(char_list)):
        if i % 2 == 0:
            if char_list[i] is "1":
                continue
            else:
                count2 += 1
        else:
            if char_list[i] is "0":
                continue
            else:
                count2 += 1
    print(min(count1,count2))
K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1)
        if x+y+z == S:
            count += 1
print(count)

### FIXED CODE ###

K, S = map(int, input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x+y)
        if (z <= K) & (z >= 0):
            count += 1
print(count)
n=int(input())
ans=0
for i in range(n):
    x,u=input().split()
    if u="BTC":
        ans+=380000*float(x)
    else:
        ans+=int(x)
print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(n):
    x,u=input().split()
    if u=="BTC":
        ans+=380000*float(x)
    else:
        ans+=int(x)
print(ans)
N, L = [int(x) for x in input().split()]
S = [input() for _ in range(N)]
S.sort(key=lambda x: -x)
print("".join(S[:L]))

### FIXED CODE ###

N, L = [int(x) for x in input().split()]
print("".join(sorted([input() for _ in range(N)],reverse=False)))
n, k = map(int, input().split())

if n%k==0:
	print(0)
else:
	pritn(1)

### FIXED CODE ###

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

if n%k!=0:
	print(1)
else:
	print(0)
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N-1)]
A.sort()
 
cost=[0]*(N+1)
 
for _ in range(Q):
	a,b=map(int,input().split())
	cost[a]+=b
 
for a in A:
	cost[a[1]] += cost[a[0]]
print(*cost[1:])
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N-1)]
A.sort()

cost=[0]*(N+1)

for _ in range(Q):
	a,b=map(int,input().split())
	cost[a]+=b

for a in A:
	cost[a[1]] += cost[a[0]]
print(*cost[1:])


### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
  print(s)
else:
  print('red')
import numpy as np
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(csr_matrix(array, dtype=np.bool, shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))

### FIXED CODE ###

import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))
import numpy as np

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]
xleft = x - l
xright = x + l

count = 0
i = 0
while i < N - 1:
    if xright[i] > xright[i + 1]:
        count += 1
        i += 1
    else:
        for j in range(i + 1, N):
            if xright[i] > xleft[j]:
                count += 1
                j = j + 1
            else:
                i = j
                break
        else:
            i = N - 1

print(N - count)

### FIXED CODE ###

N, K, S = map(int, input().split())
a = [S] * K
if S < 1000000000:
    b = [S + 1] * (N - K)
else:
    b = [S - 1] * (N - K)
print(' '.join(map(str, a + b)))
import math
import sys
sys.setrecursionlimit(2000000)
n, x = map(int, input().split())
xl = [int(_) for _ in input().split()]
for i in range(n):
    if x > xl[i]:
        xl[i] = x - xl[i]
    else:
        xl[i] = xl[i] - x
x_gcd = xl[0]
if n > 1:
    for i in range(1, n):
        x_gcd = math.gcd(x_gcd, xl[i])
print(x_gcd)


### FIXED CODE ###

n, x = map(int, input().split())
xl = [int(_) for _ in input().split()]
for i in range(n):
    if x > xl[i]:
        xl[i] = x - xl[i]
    else:
        xl[i] = xl[i] - x


def gcd(a, b):
    if a < b:
        x_a = b
        x_b = a
    else:
        x_a = a
        x_b = b
    while(1):
        if x_a < x_b:
            tmp = x_a
            x_a = x_b
            x_b = tmp
        x_a %= x_b
        if x_a == 0:
            break
    return x_b

    
x_gcd = xl[0]
if n > 1:
    for i in range(1, n):
        x_gcd = gcd(x_gcd, xl[i])
print(x_gcd)
from itertools import permutations
from copy import deepcopy

n,a,b,c = map(int,input().split())
take = []
for _ in range(n):
	take.append(int(input()))
tmp = deepcopy(take)
ans_list = []
for abc in permutations([a,b,c],3):
	take = deepcopy(tmp)
	sum_take = sum(take)
	ans = 0
	l = []
	l2 = []
	s = set(take)
	#print(s)
	for x in abc:
		res = []
		l2 = []
		take = list(s)
		for i in range(2**n):
			l = []
			for j in range(len(take)):
					if i & (1<<j):
						l.append(take[j])
			if len(l) == 0:
				continue
			res.append(10*(len(l)-1) + abs(sum(l) - x))
			l2.append(set(l))
		minimum = sum_take
		for i in range(len(res)):
			if minimum > res[i]:
				minimum = res[i]
				s2 = l2[i]
		s = s - s2
		ans += minimum
		#print(res,s,minimum)
	ans_list.append(ans)

print(min(ans_list))


### FIXED CODE ###

from itertools import permutations
from copy import deepcopy
from collections import Counter

n,a,b,c = map(int,input().split())
take = []
for _ in range(n):
	take.append(int(input()))
tmp = deepcopy(take)
ans_list = []

sum_abc = 10 ** 5
for abc in permutations([a,b,c],3):
	take = deepcopy(tmp)
	ans = 0
	l = []
	l2 = []
	s = Counter(take)
	#print(s)
	for x in abc:
		res = []
		l2 = []
		take = []
		for i,num in s.items():
			for j in range(num):
				take.append(i)
		#take = list(s)
		for i in range(2**n):
			l = []
			for j in range(len(take)):
					if i & (1<<j):
						l.append(take[j])
			if len(l) == 0:
				continue
			res.append(10*(len(l)-1) + abs(sum(l) - x))
			l2.append(l)
		minimum = sum_abc
		for i in range(len(res)):
			if minimum > res[i]:
				minimum = res[i]
				s2 = l2[i]
		for i in range(len(s2)):
			s[s2[i]] -= 1
			if s[s2[i]] == 0:
				s.pop(s2[i])
		#s = s - s2
		ans += minimum
		#print(res,s,minimum)
	ans_list.append(ans)

print(min(ans_list))
bill_count, total_money = map(int, input().split())

def calc(total_money, bill_count):
  x_high_bound = int(total_money / 10000) if int(total_money / 10000) < bill_count else bill_count
  for x in range(x_high_bound + 1):
    hoge = bill_count - x
    if 10000 * x + 5000 * hoge < total_money: continue
    if 10000 * x + 1000 * hoge > total_money: continue
    for y in range(hoge + 1):
      for z in [bill_count - x - y]:
        if 10000 * x + 5000 * y + 1000 * z == total_money:
          return f'{x} {y} {z}'
  return '-1 -1 -1'

print(calc(total_money, bill_count))

### FIXED CODE ###

bill_count, total_money = map(int, input().split())
patterns = [
  (x, y, bill_count - x - y) 
    for x in range(bill_count + 1) 
      for y in range(bill_count - x + 1) 
    if 10000*x + 5000*y + 1000*(bill_count - x - y) == total_money
]
print(" ".join(map(str, patterns[0])) if len(patterns) > 0 else '-1 -1 -1')