Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.

There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly q_{i} items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the q_{i} items in the cart.

Maxim now needs to buy n items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well.

Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.


-----Input-----

The first line contains integer m (1 ≤ m ≤ 10^5) — the number of discount types. The second line contains m integers: q_1, q_2, ..., q_{m} (1 ≤ q_{i} ≤ 10^5). 

The third line contains integer n (1 ≤ n ≤ 10^5) — the number of items Maxim needs. The fourth line contains n integers: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^4) — the items' prices.

The numbers in the lines are separated by single spaces.


-----Output-----

In a single line print a single integer — the answer to the problem.


-----Examples-----
Input
1
2
4
50 50 100 100

Output
200

Input
2
2 3
5
50 50 50 50 50

Output
150

Input
1
1
7
1 1 1 1 1 1 1

Output
3



-----Note-----

In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.

In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.

Difficulty: MEDIUM
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
def main():
	input()
	q = min(map(int, input().split()))
	input()
	aa = sorted(map(int, input().split()), reverse=True)
	print(sum(aa) - sum(aa[q::q + 2]) - sum(aa[q + 1::q + 2]))
main()


(m, mSale) = (int(input()), list(map(int, input().split())))
(n, nPrice) = (int(input()), list(map(int, input().split())))
nPrice.sort()
(sum, small) = (0, min(mSale))
while True:
	if len(nPrice) <= small:
		for k in nPrice:
			sum += k
		print(sum)
		return
	else:
		for i in range(small):
			sum += nPrice.pop()
		if len(nPrice) <= 2:
			print(sum)
			return
		else:
			for i in range(2):
				nPrice.pop()


m = int(input())
dis = list(map(int, input().split()))
n = int(input())
p = list(map(int, input().split()))
p.sort(reverse=True)
dis.sort()
money = sum(p)
mind = dis[0]
if n <= mind:
	print(sum(p))
else:
	i = mind - 1
	while i < n:
		if i + 1 < n:
			money -= p[i + 1]
		if i + 2 < n:
			money -= p[i + 2]
		i += mind + 2
	print(money)


from sys import stdin
__author__ = 'artyom'

def read_int():
	return int(stdin.readline().strip())

def read_int_ary():
	return map(int, stdin.readline().strip().split())
m = read_int()
d = sorted(read_int_ary())[0]
n = read_int()
a = list(reversed(sorted(read_int_ary())))
res = i = 0
while i < n:
	next = i + d
	res += sum(a[i:min(next, n)])
	i = next + 2
print(res)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def factors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac
n = int(input())
q = sorted(list(map(int, input().split())))
m = int(input())
m = sorted(list(map(int, input().split())))
m = m[::-1]
i = 0
j = 0
sumi = 0
while j < len(m):
	for k in range(j, min(j + q[i], len(m))):
		sumi += m[k]
		j += 1
	j += 2
print(sumi)


import sys
input = sys.stdin.readline
for _ in range(1):
	n = int(input())
	temp = [int(x) for x in input().split()]
	m = int(input())
	arr = [int(x) for x in input().split()]
	now = min(temp)
	i = m - 1
	ans = 0
	arr.sort()
	while i >= 0:
		curr = 0
		while i >= 0 and curr < now:
			ans += arr[i]
			curr += 1
			i -= 1
		i -= 2
	print(ans)


a = int(input())
q = list(map(int, input().split()))
n = int(input())
cost = list(map(int, input().split()))
t = min(q)
cost.sort()
total = 0
index = len(cost) - 1
while index >= 0:
	r = t
	if index >= t:
		r = t
		while r:
			total += cost[index]
			r -= 1
			index -= 1
		if index >= 2:
			index -= 2
		else:
			break
	else:
		total += sum(cost[0:index + 1])
		break
print(total)


m = int(input())
q = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
q.sort()
a.sort()
j = n - 1
i = 0
ans = 0
while j >= 0:
	for i in range(q[0]):
		ans = ans + a[j]
		j = j - 1
		if j < 0:
			break
	j = j - 2
print(ans)


m = int(input())
q = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
mn = min(q)
a.sort(reverse=True)
(ans, p) = (0, 0)
while 1:
	for i in range(p, min(p + mn, n)):
		ans += a[i]
	p += mn + 2
	if p >= n:
		break
print(ans)


input()
k = min(map(int, input().split()))
n = int(input())
p = sorted(map(int, input().split()), reverse=True) + [0] * k
print(sum((sum(p[i:i + k]) for i in range(0, n, k + 2))))


m = int(input())
q = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
q.sort()
ans = 0
mm = q[0]
i = 0
while i < n:
	j = i
	if j + mm <= n:
		while i < j + mm:
			ans += a[i]
			i += 1
		i += 1
	else:
		break
	i += 1
if i < n:
	ans += sum(a[i:])
print(ans)


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
m = int(input())
di = sorted([int(i) for i in input().split()])
d = di[0]
n = int(input())
l = sorted([int(i) for i in input().split()])
c = 0
i = n - 1
c1 = 0
while i > -1:
	if c1 == d:
		i -= 2
		c1 = 0
	else:
		c1 += 1
		c += l[i]
		i -= 1
print(c)


import sys
input = sys.stdin.readline
m = int(input())
q = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
discount = min(q)
a.sort(reverse=True)
ans = 0
for i in range(0, n, discount + 2):
	ans += sum([a[i] for i in range(i, min(i + discount, n))])
print(ans)


input()
I = lambda : map(int, input().split())
(q, n, a, r, k) = (min(I()), int(input()) - 1, sorted(I()), 0, 0)
while n > -1:
	r += a[n]
	k += 1
	if k == q:
		n -= 3
		k = 0
	else:
		n -= 1
print(r)


discounts = int(input())
discount_values = list(map(int, input().split()))
target = int(input())
item_values = list(map(int, input().split()))
discount_values.sort()
item_values.sort()
item_values.reverse()
basket_size = discount_values[0]
result = 0
bought = 0
counter = 0
while bought < target:
	if target - bought < basket_size:
		result += sum(item_values[counter:])
		bought += target + 1
	else:
		bought += 2 + basket_size
		result += sum(item_values[counter:counter + basket_size])
		counter += 2 + basket_size
print(result)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def main():
	m = inpu()
	q = lis()
	n = inpu()
	arr = lis()
	q = min(q)
	arr.sort(reverse=True)
	s = 0
	cnt = 0
	i = 0
	while i < n:
		cnt += 1
		s += arr[i]
		if cnt == q:
			i += 2
			cnt = 0
		i += 1
	print(s)
main()


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	a = sorted(lst())
	d = a[0]
	n = nmbr()
	a = sorted(lst())
	ans = 0
	p = n - 1
	buy = d
	while p >= 0:
		if d == 0:
			d = buy
			p -= 2
			continue
		ans += a[p]
		d -= 1
		p -= 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
m = int(input())
c = list(map(int, input().split()))
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
k = min(c)
i = 0
s = 0
while i < n:
	s += sum(l[i:i + k])
	i += k + 2
print(s)


import math

def sort(arr):
	swap = True
	i = 0
	while swap == True or i > len(arr):
		swap = False
		for j in range(len(arr) - i - 1):
			if arr[j] > arr[j + 1]:
				temp = arr[j]
				arr[j] = arr[j + 1]
				arr[j + 1] = temp
				swap = True
		i += 1
need = []
items = []
m = input()
need = input().split()
for i in range(len(need)):
	need[i] = int(need[i])
n = eval(input())
items = input().split()
for i in range(len(items)):
	items[i] = int(items[i])
need.sort()
items.sort()
start = 0
total = 0
while n > 0:
	if math.trunc(n / (need[0] + 2)) > 0:
		for j in range(need[0]):
			total += items[n - 1 - j]
		n = n - int(need[0]) - 2
	elif math.trunc(n / (need[0] + 1)) > 0:
		for j in range(need[0]):
			total += items[n - 1 - j]
		n = n - int(need[0]) - 1
	else:
		for j in range(n):
			total += items[n - 1 - j]
		n = 0
print(total)


import sys, math

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
m = int(input())
discount = get_ints()
discount = sorted(discount)
n = int(input())
prices = get_ints()
prices = sorted(prices)
prices = prices[::-1]
index = 0
totalprice = 0
flag = 0
ans = 0
while True:
	dis = discount[0]
	if index >= n:
		flag = 1
		break
	for i in range(dis):
		if index >= n:
			flag = 1
			break
		ans += prices[index]
		index += 1
	if flag == 1:
		break
	index += 2
	if flag == 1:
		break
if flag == 1:
	print(ans)
else:
	for i in range(index, n):
		ans += prices[index]
	print(ans)


a = input()
b = sorted([int(i) for i in input().split()])[0]
c = int(input())
d = sorted([int(i) for i in input().split()])
p = 0
while len(d):
	for i in range(0, min(len(d), b)):
		p += d.pop()
	for i in range(0, min(len(d), 2)):
		a = d.pop()
print(p)


m = int(input())
q = list(map(int, input().split()))
c = min(q)
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n):
	if i % (c + 2) < c:
		res += a[n - 1 - i]
print(res)


class CodeforcesTask261ASolution:

	def __init__(self):
		self.result = ''
		self.discounts = []
		self.items_count = 0
		self.prices = []

	def read_input(self):
		input()
		self.discounts = [int(x) for x in input().split(' ')]
		self.items_count = int(input())
		self.prices = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.discounts.sort()
		self.prices.sort(reverse=True)
		price = 0
		discount = self.discounts[0]
		for x in range(self.items_count):
			if x % (discount + 2) < discount:
				price += self.prices[x]
		self.result = str(price)

	def get_result(self):
		return self.result

def __starting_point():
	Solution = CodeforcesTask261ASolution()
	Solution.read_input()
	Solution.process_task()
	print(Solution.get_result())
__starting_point()


input()
d = [int(i) for i in input().split()]
c = int(input())
b = [int(i) for i in input().split()]
b.sort()
take = 1
p = min(d)
s = 0
buy = p
for i in reversed(b):
	if buy:
		s += i
		buy -= 1
	elif take:
		take -= 1
	else:
		buy = p
		take = 1
print(s)


nq = int(input())
q = [int(x) for x in input().split()]
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
m = min(q)
i = 0
ans = 0
x = 0
while i < n:
	if x == m:
		x = 0
		i += 2
		continue
	x += 1
	ans += a[i]
	i += 1
print(ans)


m = int(input())
q = [int(i) for i in input().split()]
n = int(input())
a = [int(i) for i in input().split()]
c = min(q)
a.sort()
price = 0
for i in range(n):
	if i % (c + 2) < c:
		price += a[n - 1 - i]
print(price)


m = int(input())
q = [int(i) for i in input().split()]
q.sort()
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = 0
i = n - 1
while i >= 0:
	d = 0
	while i >= 0 and d < q[0]:
		ans += a[i]
		i -= 1
		d += 1
	d = 0
	while i >= 0 and d < 2:
		d += 1
		i -= 1
print(ans)


import sys
n_discounts = int(sys.stdin.readline())
discount_values = [int(x) for x in sys.stdin.readline().split()]
n_items = int(sys.stdin.readline())
item_values = [int(x) for x in sys.stdin.readline().split()]
min_discount_req = 10000000
for discount_value in discount_values:
	min_discount_req = min(min_discount_req, discount_value)
item_values.sort(reverse=True)
index = 0
overall_price = 0
while index < n_items:
	n_left = min(min_discount_req, n_items - index)
	for i in range(n_left):
		overall_price += item_values[index + i]
	index += n_left + 2
print(overall_price)


m = int(input())
lstm = list(map(int, input().strip().split(' ')))
n = int(input())
lstn = list(map(int, input().strip().split(' ')))
m1 = min(lstm)
lstn.sort(reverse=True)
i = 0
s = 0
while i < n:
	if i + m1 <= n:
		s += sum(lstn[i:i + m1])
		i += m1
		if i + 2 <= n:
			i += 2
		elif i + 1 <= n:
			i += 1
	else:
		s += sum(lstn[i:n])
		i = n
print(s)


m = int(input())
carts = [int(x) for x in input().split()]
n = int(input())
cost = [int(x) for x in input().split()]
x = min(carts)
bought = 0
free = 0
cost = sorted(cost, reverse=True)
amt = 0
for i in cost:
	if free > 0:
		free -= 1
		continue
	amt += i
	bought += 1
	if bought == x:
		bought = 0
		free = 2
print(amt)


m = int(input())
q = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
sk = min(q)
a.sort()
j = 1
ans = 0
for i in range(n - 1, -1, -1):
	l = sk - j
	if l == -1:
		pass
	elif l == -2:
		j = 0
	else:
		ans += a[i]
	j += 1
print(ans)